使用 jquery 自动滚动到页面底部
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1966784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
auto scroll to bottom of page with jquery
提问by Web Worm
How can i auto scroll to bottom of page with jquery becuase i am requesting xmlhttp to update content of page
我如何使用 jquery 自动滚动到页面底部,因为我请求 xmlhttp 来更新页面的内容
回答by Tatu Ulmanen
This will work in every case, no need to put a 'ridiculous' number in it:
这在任何情况下都有效,无需在其中输入“荒谬”的数字:
$(document).scrollTop($(document).height());
回答by Gyuri Ambrozy
To cover all scenarios: Consider scrolling an overflowed div where height is not the same as scrollHeight. (remove the animate part if its not needed):
涵盖所有场景:考虑滚动高度与 scrollHeight 不同的溢出 div。(如果不需要,请删除动画部分):
$('#myDiv').animate({
scrollTop: $('#myDiv').get(0).scrollHeight
}, 1500);
回答by nice
in my case it's:
就我而言,它是:
myscroll = $('#myDiv');
myscroll.scrollTop(myscroll.get(0).scrollHeight);
回答by Pranit
This Code work for me:-
此代码对我有用:-
jQuery("html, body").animate({ scrollTop: jQuery(window).height()}, 1500);
回答by Pranit
Try the ScrollTo plugin
回答by awolf
function scroll(){
$('html, body').animate({
scrollTop: $("#footerOfPage").offset().top
}, 0);
}
回答by ramin
回答by Jorge Olivero
A lot of the scrollHeight implementations didn't work for me, offsetHeight seemed to do the trick.
许多 scrollHeight 实现对我不起作用,offsetHeight 似乎可以解决问题。
Pretty sure that scrollHeight tries to move it to the bottom of the height of the static element, not the height of the scrollable area.
非常确定 scrollHeight 试图将其移动到静态元素高度的底部,而不是可滚动区域的高度。
var pane = document.getElementById('pane');
pane.scrollTop = pane.offsetHeight;