有人能建议这个网站如何使用jQuery Masonry插件来实现其快速、流畅的布局吗?
http://tympanus.net/codrops/collective/collective-2/
具体而言;
浏览器调整大小时,列数从3到2再到1,这是您对使用砖石结构的网站的期望,但有趣的是,列也会调整大小,以始终填充可用的全宽。我见过的大多数其他砖石建筑工地都会随着柱子数量的变化在柱子右侧留下空隙(例如http://masonry.desandro.com/)OR列填满了整个宽度,但列数保持不变(http://masonry.desandro.com/demos/fluid.html)。他们是在结合CSS媒体查询动态设置浏览器调整大小的列数,还是使用CSS3列?
谢谢。
这是我们正在查看的代码。
jQuery(document).ready(function($) {
var CollManag = (function() {
var $ctCollContainer = $('#ct-coll-container'),
collCnt = 1,
init = function() {
changeColCnt();
initEvents();
initPlugins();
},
changeColCnt = function() {
var w_w = $(window).width();
if( w_w <= 600 ) n = 1;
else if( w_w <= 768 ) n = 2;
else n = 3;
},
initEvents = function() {
$(window).on( 'smartresize.CollManag', function( event ) {
changeColCnt();
});
},
initPlugins = function() {
$ctCollContainer.imagesLoaded( function(){
$ctCollContainer.masonry({
itemSelector : '.ct-coll-item',
columnWidth : function( containerWidth ) {
return containerWidth / n;
},
isAnimated : true,
animationOptions: {
duration: 400
}
});
});
$ctCollContainer.colladjust();
$ctCollContainer.find('div.ct-coll-item-multi').collslider();
};
return { init: init };
})();
CollManag.init();
});
其基本思想似乎是添加一个列选择器,用于确定可以设置的列数。第二步是在函数中使用smartresize事件。第三步是将砌体称为具有"动态"宽度的柱。玩得开心:)