我使用的类无限滚动插件由保罗爱尔兰。我的基本HTML结构是这样的:
<div class="container">
<div class="track">
a bunch of other html
</div>
<div class="track">
a bunch of other html
</div>我有大约100首曲目,每首曲目以10个为一组进行分页。对分页的调用工作正常,所以我不会包含这些代码。下面是我的无限滚动jQuery代码:
jQuery(function($) {
$('.charts-container').infinitescroll({
navSelector: '.navigation',
nextSelector: '.next-page',
itemSelector: '.track',
loading: { img: "<?php echo get_template_directory_uri() . '/images/ajax-loader-spinner.gif'; ?>",
msgText: '',
finishedMsg: ''
}
}, function(arrayOfNewElems) {
// bind newly generated audio elements -- media events don't bubble
$('audio').on('ended', function(e) {
$(e.currentTarget).prev('.play-button').find('.pause-img').addClass('js-hidden');
$(e.currentTarget).prev('.play-button').find('.play-img').removeClass('js-hidden');
});
});这是可行的。它获得适当的数据并正确地填充页面,顺利地执行回调。问题是,当我开始在页面上滚动时,加载就开始了,所以在我甚至远距离接近页面底部之前,已经加载了20首曲目,其余的很快就加载了。
这就像是其他什么东西触发了无限滚动,因为它肯定不是我在屏幕上的位置。当页面加载时,看不到容器的底部。是什么触发了这一切呢?这不是回调,因为我最近才添加了回调,而且我以前遇到过这些问题。
发布于 2013-11-07 05:10:49
你可以稍微修改一下,然后试试这个:
$(window).scroll(function() {
if($(window).offset().bottom < 200) {
$(".charts-container").DoSomething//ETC...
}
});这将仅当viewport为从底部算起的200px时触发该函数。
https://stackoverflow.com/questions/19822048
复制相似问题