01
<script type=
"text/javascript"
>
02
var
flag =
true
;
03
$(
function
(){
04
$container = $(
'#listing'
);
05
$container.masonry({
06
singleMode:
,
07
animate:
08
itemSelector:
'.post'
09
});
10
//滚动条滚动到离底部距离50的时候触发
11
$(window).scroll(
12
// 当滚动到最底部以上100像素时, 加载新内容
13
if
($(document).height() - $(
this
).scrollTop() - $(
).height()<50){
14
(flag){
15
$boxes = $(getList());
16
$container.append($boxes).masonry(
'appended'
,$boxes);
17
}
18
19
20
21
//测试获取列表
22
getList() {
23
boxes = [],count = parseInt(Math.random()*10);
24
for
(
i=0; i < count; i++ ) {
25
boxes.push(
'<div class="post"><a href="#"><img src="images/'
+(i+1)+
'.jpg" width="280" alt="" /></a><a href="#" target="_blank">图片'
'</a></div>'
26
27
//把数组转成字符串
28
return
boxes.join(
""
29
};
30
</script>