【发布时间】:2015-04-28 17:45:33
【问题描述】:
我想知道一个连续网站的代码,如果我滚动到底部并返回顶部,否则。
我已经在一半的地方使用此代码作为底部页面:
$(document).ready(function() {
$(document).scroll(function(){
if (document.documentElement.clientHeight + $(window).scrollTop() >= $(document).height()) {
$(document).scrollTop(0);
}
});
});
我怎么能反过来呢? 从顶部到底部页面?
编辑:
$(document).ready(function() {
$(document).scroll(function(){
if (document.documentElement.clientHeight + $(window).scrollTop() >= $(document).height()) {
$(document).scrollTop(0);
}
else if ($(window).scrollTop() <= 0) {
$(document).scrollTop($(document).height());
}
});
});
我尝试了该代码并且它可以工作,但我认为那里有一个小错误,我需要再滚动一点才能从顶部到达底部,否则为什么会发生这种情况?
谢谢
【问题讨论】:
标签: javascript jquery html infinite-scroll