[英]How do I programatically scroll down the page?
When the page loads, I want to use Javascript/Jquery to automatically take the user to the 500px downwards. 页面加载后,我想使用Javascript / Jquery自动将用户带到500px下方。 But it has to seem natural.
但这似乎很自然。
How can that be done? 那怎么办?
只是Javascript: window.scrollBy(0,500);
You can use the jquery scrollto plugin. 您可以使用jquery scrollto插件。 It's very easy.
很简单
http://plugins.jquery.com/scrollTo/ http://plugins.jquery.com/scrollTo/
Is there a lighter version?
有较轻的版本吗? Just using javascript?
只是使用JavaScript?
You could consider calling window.location.hash
during onload. 您可以考虑在onload期间调用
window.location.hash
。 Have an element with an ID at about 500px down and just do 有一个ID向下大约500px的元素,然后执行
window.onload = function() {
window.location.hash = '#foo';
}
Oh, the #
is mandatory for IE compatibility ;) 哦,
#
是IE兼容性必需的;)
use the jquery one Jourkey suggested. 使用一个Jourkey建议的jquery。 Cross platform easy to use etc. There is pure JavaScript one you can try, though YMMV on browsers other than IE
跨平台易于使用等。您可以尝试使用纯JavaScript,尽管在IE以外的浏览器上使用YMMV
" scrollTo Method
“ scrollTo方法
Scrolls the window to the specified x- and y-offset. 将窗口滚动到指定的x和y偏移。 "
”
http://msdn.microsoft.com/en-us/library/ms536731(VS.85).aspx http://msdn.microsoft.com/zh-cn/library/ms536731(VS.85).aspx
$().scrollTop(500);
What about navigating to some predefined link inside the page. 导航到页面内的一些预定义链接该怎么办。 Foe example see URL pointing to the location inside the page http://en.wikipedia.org/wiki/Uniform_Resource_Locator#cite_note-0
仇敌示例,请参见指向页面内部位置的URL http://en.wikipedia.org/wiki/Uniform_Resource_Locator#cite_note-0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.