我有一个小脚本,允许我的用户在不重新加载页面或使用分页的情况下接收新项目。
我有一个非常大的页脚,其中包含一些信息,目前只有当用户到达页面底部时才会加载此脚本。
无论如何你可以这么做,如果用户在页面上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>
答案 0 :(得分:4)
超级简单。只有$('body').height()
乘以0.9。
<script type="text/javascript">
alreadyloading = false;
start = 20;
stop = 30;
$(window).scroll(function() {
if (($(window).scrollTop + $(window).height()) >= ($('body').height() * 0.9)) {
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>
答案 1 :(得分:0)
$(window).scroll(function() {
a = document.documentElement.scrollTop;
b = document.body.scrollTop;
c = document.documentElement.scrollHeight;
d = document.documentElement.clientHeight;
prg = Math.round(((a+b) /(c-d))*100);
});