我有一个小脚本,允许我的用户接收新的项目,而无需重新加载页面或使用分页。
我有一个相当大的页脚与一些信息,目前这个脚本只加载时,用户到达页面底部。
有没有什么方法可以让它在用户浏览了页面的90%后,函数就启动了?
以下是我目前的脚本:
<script type="text/javascript">
alreadyloading = false;
start = 20;
stop = 30;
$(window).scroll(function() {
if ($('body').height() <= ($(window).height() + $(window).scrollTop())) {
if (alreadyloading == false) {
alreadyloading = true;
$('.last').show();
$.ajax({
type: "GET",
url: "/trophy-room/all/",
data: "start="+start+"&stop="+stop,
success: function(data) {
$(data).insertBefore('.last');
start = stop;
stop = stop + 10;
$('.last').hide();
alreadyloading = false;
}
});
// if you reach bottom, send 10 as begging and 20 as stop
// load the data and insert before div last or something. [5:10]
}
}
});
</script>
2条答案
按热度按时间eoigrqb61#
超级简单,
$('body').height()
乘以0.9。ne5o7dgx2#
哦,比我早一点。但是这里有另一个解决方案。检查“prg”。
});