我正在使用动态数据的无限滚动,但似乎无法超越第2页......
当页面最初加载时,我在URL中有一个偏移量,所以我们从0开始,所以,
test2.html?offset=0
这是加载日期的代码
$offset = $_GET['offset'];
$data = mysql_query("select * from list limit 30 offset $offset;",$db);
echo '<div id="wall" class="transitions-enabled infinite-scroll clearfix">';
while ($databack33 = mysql_fetch_array($data)){
echo '<div class="block">';
echo '<a href=#><img src="'.$databack33[item_pic_url].'"></a>';
echo '</div>';
}
然后加载我使用的下一页:
<nav id="page-nav">
<? $offset = $offset+30; ?>
<a href="test2.html?offset=<?=$offset?>"></a>
</nav>
这适用于第一页和第二页,但它告诉我不再需要加载页面,尽管有更多数据。
如果我查看页面来源,它是正确的test2.html?offset=60
这是砌筑/无限卷轴设置
<script type="text/javascript">
$(function(){
var $container = $('#wall');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector: '.block',
isAnimated: true,
animationOptions: {
duration: 750,
easing: 'linear',
queue: false
}
});
});
$container.infinitescroll({
navSelector : '#page-nav', // selector for the paged navigation
nextSelector : '#page-nav a', // selector for the NEXT link (to page 2)
itemSelector : '.block', // selector for all items you'll retrieve
loading: {
finishedMsg: 'No more pages to load.',
img: 'http://i.imgur.com/6RMhx.gif'
}
},
// trigger Masonry as a callback
function( newElements ) {
// hide new items while they are loading
var $newElems = $( newElements ).css({ opacity: 0 });
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded(function(){
// show elems now they're ready
$newElems.animate({ opacity: 1 });
$container.masonry( 'appended', $newElems, true );
});
}
);
});
</script>
答案 0 :(得分:1)
要使infinitescroll使用“offset =”分页,我执行了以下操作:
存储当前的“下一页”网址,并获取偏移值。
var nextSelector = '#page-nav a';
var origNextUrl = $(nextSelector).attr('href');
var offsetRegex = /(offset=)([0-9]+)/;
var offset = origNextUrl.match(offsetRegex)[2];
然后在infinitescroll中为“path”选项分配一个函数,该选项接受页码并返回用于加载下一页的URL。
$container.infinitescroll({
// other options
path: function(pageNum) {
return origNextUrl.replace( offsetRegex, ("$1" + (offset * pageNum)) );
},
//callback
});