有没有替代jQuery无限滚动插件的方法?
http://www.beyondcoding.com/2009/01/15/release-jquery-plugin-endless-scroll/
发布于 2011-01-30 15:48:09
例如,infinite scroll plugin
发布于 2011-01-30 17:50:57
这应该可以在没有插件的情况下完成相同的操作
$(window).scroll(function () {
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 100) {
//Add something at the end of the page
}
});
编辑2014年1月15日
根据@pere的评论,最好使用下面的代码来避免过多的事件触发。
从这个答案中获得灵感https://stackoverflow.com/a/13298018/153723
var scrollListener = function () {
$(window).one("scroll", function () { //unbinds itself every time it fires
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 100) {
//Add something at the end of the page
}
setTimeout(scrollListener, 200); //rebinds itself after 200ms
});
};
$(document).ready(function () {
scrollListener();
});
发布于 2012-11-06 20:04:32
结合Ergec的回答和Pere的评论:
function watchScrollPosition(callback, distance, interval) {
var $window = $(window),
$document = $(document);
var checkScrollPosition = function() {
var top = $document.height() - $window.height() - distance;
if ($window.scrollTop() >= top) {
callback();
}
};
setInterval(checkScrollPosition, interval);
}
distance
是从屏幕底部开始触发回调时的像素数。
interval
是运行检查的频率(以毫秒为单位;250-1000是合理的)。
https://stackoverflow.com/questions/4841585
复制相似问题