问题描述
页面加载完成后.我希望jQUery能够很好地滚动到页面底部,快速动画,而不是快速/摇动.
After my page is done loading. I want jQUery to nicely scroll to the bottom of the page, animating quickly, not a snap/jolt.
我是否需要像ScrollTo
这样的插件?还是jQuery内置的某种方式?
Do iI need a plugin like ScrollTo
for that? or is that built into jQuery some how?
推荐答案
您可以通过设置scrollTop
属性的动画来动画化向下滚动页面,而无需插件,例如:
You can just animate to scroll down the page by animating the scrollTop
property, no plugin required, like this:
$(window).load(function() {
$("html, body").animate({ scrollTop: $(document).height() }, 1000);
});
请注意使用window.onload
(当加载图像时...占据高度)而不是document.ready
.
Note the use of window.onload
(when images are loaded...which occupy height) rather than document.ready
.
要在技术上正确无误,您需要减去窗口的高度,但以上方法可以实现:
To be technically correct, you need to subtract the window's height, but the above works:
$("html, body").animate({ scrollTop: $(document).height()-$(window).height() });
要滚动到特定ID,请使用其 .scrollTop()
,如下所示:
To scroll to a particular ID, use its .scrollTop()
, like this:
$("html, body").animate({ scrollTop: $("#myID").scrollTop() }, 1000);
这篇关于jQuery滚动到页面底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!