function addScrollListener(){
$(window).bind("scroll", function() {
var scrollTop = $(document).scrollTop();
var totalHeight = document.body.scrollHeight;
var windowHeight = $(window).height();
if ((scrollTop + windowHeight) / totalHeight > 0.8) {
var htmlString = getHtml();
var newHtmlString ="" ;
newHtmlString = newHtmlString+htmlString;
$("#view").append(newHtmlString);
}
})
$(window).bind("scroll", function() {
var scrollTop = $(document).scrollTop();
var totalHeight = document.body.scrollHeight;
var windowHeight = $(window).height();
if ((scrollTop + windowHeight) / totalHeight > 0.8) {
var htmlString = getHtml();
var newHtmlString ="" ;
newHtmlString = newHtmlString+htmlString;
$("#view").append(newHtmlString);
}
})
本文介绍了一个使用jQuery实现的简单功能,即当用户滚动到页面底部时自动加载更多内容。通过监听窗口滚动事件并计算当前滚动位置与整个文档高度的比例来判断是否触发加载新内容。
3060

被折叠的 条评论
为什么被折叠?



