gpt4 book ai didi

javascript - jQuery Infinite-Scroll - 快速滚动时事件会触发多次

转载 作者:行者123 更新时间:2023-11-29 10:51:10 28 4
gpt4 key购买 nike

如果我滚动页面,jQuery Infinite Scroll 的事件将触发两次(三次中的两次)。我怎样才能避免这种情况发生?加载下一页时,无法触发 jQuery Infinite Scroll 的事件,谢谢。

$(function(){
var speed = 1000;
var container = $('#sharelist');
container.imagesLoaded(function(){
container.masonry({
itemSelector: '.share',
singleMode: true,
columnWidth: 242,
isFitWidth: true,
animate: true,
animationOptions: {
duration: speed,
queue: false
}
});
});
container.infinitescroll({
navSelector : '.page',
nextSelector : 'a.next',
itemSelector : 'div[class=share]',
loading: {
finishedMsg: '报告,后面没有了哦.',
img: 'image/icon_waiting.gif',
msgText:'加载中'
}
},
function( newElements ) {
var newElems = $(newElements).css({ opacity: 0 });
newElems.imagesLoaded(function(){
newElems.animate({ opacity: 1 });
container.masonry( 'appended', newElems, true );
$('.namecard').floatUserInfo();
});
}
);
$("img").lazyload({
placeholder : "image/grey.gif",
effect : "fadeIn"
});
});

最佳答案

有很多关于限制调整大小事件的现有文献,您在这里也有基本相同的担忧。典型的解决方案包括调度一个异步处理程序,然后一次只允许一个处理程序挂起。最稳健(?)的方法是取消并替换旧的处理程序。

例如:

http://benalman.com/code/projects/jquery-throttle-debounce/examples/throttle/

关于javascript - jQuery Infinite-Scroll - 快速滚动时事件会触发多次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9971006/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com