masonry ajax瀑布流,瀑布流masonry布局API

本文详细介绍Masonry,一款用于整理不规则高度div的jQuery插件,配置选项包括动画效果、列宽、容器样式等,适合创建响应式和整齐的网页布局。方法如appended、layout和reloadItems提供了灵活的使用方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Masonry是一款很好用的jquery网页布局插件,它可以去掉不同高度div之间的空白,让你的网页看上去更加的整齐、漂亮!效果如下图所示

fdb93d4693c179b2fc7a7a2d59b063ff.png

官网插件下载地址以及详解地址:http://masonry.desandro.com/

masonry配置对象Options

Options are set with an object as second argument to the .masonry() method. All options are optional, and do not need to be set, but itemSelector and columnWidth are recommended.

$('#container').masonry({

itemSelector: '.box',

columnWidth: 240,

animationOptions: {

duration: 400

}

});

配置项目

类型

默认值

说明/示例

animationOptions

Object

{queue:false,duration:500}

Options used for jQuery animation. See the jQuery API for animate options for details. More details in Animating.

columnWidth

Integer

Width in pixels of 1 column of your grid. If no columnWidth is specified, Masonry uses the width of the first item element.

Recommended if your layout has item elements that have multiple-column widths.

To set a dynamic column width, you can pass in a function that returns the value column width. The function provides an argument for the width of the container. Use this technique for fluid or responsive layouts.

$('#container').masonry({

// set columnWidth a fraction of the container width

columnWidth: function( containerWidth ) {

return containerWidth / 5;

}

});

containerStyle

Object

{ position: 'relative' }

CSS properties applied to the container. Masonry uses relative/absolute positioning to position item elements.

gutterWidth

Integer

0

Adds additional spacing between columns.See Demo: Gutters

isAnimated

Boolean

false

Enables jQuery animation on layout changes. See Docs: Animating. More details in Animating.

isFitWidth

Boolean

false

If enabled, Masonry will size the width of the container to the nearest column. When enabled, Masonry will measure the width of the container’s parent element, not the width of the container. This option is ideal for centering Masonry layouts.See Demo: Centered.

isResizable

Boolean

true

Triggers layout logic when browser window is resized.

isRTL

Boolean

false

Enables right-to-left layout for languages like Hebrew and Arabic.See Demo: Right-to-left.

itemSelector

String

Filters item elements to selector. If not set, Masonry defaults to using the child elements of the container.

Recommended to avoid Masonry using any other hidden elements in its layout logic.

$('#container').masonry({ itemSelector: '.box' });

masonry方法Methods

Masonry offers several methods to extend functionality. Masonry’s methods follow the jQuery UI pattern.

$('#container').masonry( 'methodName', [optionalParameters] )

方法名称

说明和示例

appended

.masonry( 'appended', $content, isAnimatedFromBottom )

Triggers layout on item elements that have been appended to the container.

var $boxes = $('

$('#container').append( $boxes ).masonry( 'appended', $boxes );

Setting the isAnimatedFromBottom argument to true will enable the newly appended items to be animated from the bottom, if animation is enabled.

$('#container').append( $boxes ).masonry( 'appended', $boxes, true );

The appended method is ideal to use Masonry with Infinite Scroll, in its callback.

var $container = $('#container');

$container.infinitescroll({

// infinite scroll options...

},

// trigger Masonry as a callback

function( newElements ) {

var $newElems = $( newElements );

$container.masonry( 'appended', $newElems );

}

);

destroy

.masonry( 'destroy' )

Removes Masonry functionality completely. Returns element back to pre-initialized state.

layout

.masonry( 'layout', $items, callback )

Positions specified item elements in layout.

layout will only position specified elements, and those elements will be positioned at the end of layout. Whereas .masonry() will position all items in the Masonry instance.

option

.masonry( 'option', options )

Sets options for plugin instance. Unlike passing options through .masonry(), using the option method will not trigger layout.

// set multiple options

.masonry( 'option', { columnWidth: 120, isAnimated: false } )

reloadItems

.masonry( 'reloadItems' )

Re-collects all item elements in their current order in the DOM.

reload

.masonry( 'reload' )

Convenience method for triggering reloadItems then .masonry(). Useful for prepending or inserting items.

var $boxes = $('

$('#container').prepend( $boxes ).masonry( 'reload' );

remove

.masonry( 'remove', $items )

Removes specified item elements from Masonry instance and the DOM.

remove

加支付宝好友偷能量挖...

2012-11-16Web开发网

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值