javascript 加载完成后自动滚动到一个 div。使用jQuery
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9599673/
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 a div after finish loading. Use jquery
提问by Tran
I have a div with id=now, this div is empty and do not have any css property (no width, no height, just a hidden div). I want when browser finish load the page, then scroll to this div immediately. User do not need to click on some thing.
我有一个 id=now 的 div,这个 div 是空的,没有任何 css 属性(没有宽度,没有高度,只是一个隐藏的 div)。我想当浏览器完成加载页面时,然后立即滚动到这个 div。用户不需要点击某些东西。
Here is my html
这是我的 html
<html>
<div>Long div Lorem ipsum</div>
<div id="now"></div>
<div>Long div Lorem ipsum</div>
How to do this with jquery ?
如何用 jquery 做到这一点?
回答by visualidiot
$(function() { // when the DOM is ready...
// Move the window's scrollTop to the offset position of #now
$(window).scrollTop($('#now').offset().top);
});