Jquery瀑布流插件使用介绍

2020-05-22 22:01:56易采站长站整理

var $lowest_column=waterfall.$columns.eq(calculateLowest());//最短列
var bottom=$lowest_column.offset().top+$lowest_column.outerHeight();//最短列底部距离浏览器窗口顶部的距离
var scrollTop=document.documentElement.scrollTop||document.body.scrollTop||0;//滚动条距离
var windowHeight=document.documentElement.clientHeight||document.body.clientHeight||0;//窗口高度
if(scrollTop>=bottom-windowHeight){
render(getElements(),true);
}
},100);
}
function onResize(){//窗口缩放时重新排列
if(calculateColumns()==waterfall.column_num) return; //列数未改变,不需要重排
var $cells=waterfall.$container.find(setting.cell_selector);
waterfall.$columns.remove();
waterfall.$columns=creatColumn();
render($cells,false); //重排已有元素时强制不渐显
}
})(jQuery);

貌似把代码贴进来格式有点乱了,哎先不管了。上面的代码要是看不清可以在demo页直接查看源文件。
插件使用方法:
$(selector).waterfall(opt); //其中selector为瀑布流容器的选择器,opt为配置参数对象
所需的html结构:html结构可以就是一个空容器元素,如<div id=”container”></div>,里面的砖块元素通过动态加载进来。当然也可以预先放一些砖块进去,如demo页中的

<div id=”container”>
<div class=”cell”><img src=”P_000.jpg” /><p>00</p></div>
<div class=”cell”><img src=”P_001.jpg” /><p>01</p></div>
<div class=”cell”><img src=”P_002.jpg” /><p>02</p></div>
<div class=”cell”><img src=”P_003.jpg” /><p>03</p></div>
<div class=”cell”><img src=”P_004.jpg” /><p>04</p></div>
<div class=”cell”><img src=”P_005.jpg” /><p>05</p></div>
<div class=”cell”><img src=”P_006.jpg” /><p>06</p></div>
<div class=”cell”><img src=”P_007.jpg” /><p>07</p></div>
<div class=”cell”><img src=”P_008.jpg” /><p>08</p></div>
<div class=”cell”><img src=”P_009.jpg” /><p>09</p></div>
<div class=”cell”><img src=”P_010.jpg” /><p>10</p></div>
<div class=”cell”><img src=”P_011.jpg” /><p>11</p></div>
<div class=”cell”><img src=”P_012.jpg” /><p>12</p></div>
<div class=”cell”><img src=”P_013.jpg” /><p>13</p></div>
<div class=”cell”><img src=”P_014.jpg” /><p>14</p></div>