How do I programatically scroll down the page?

2020-08-22 02:53发布

When the page loads, I want to use Javascript/Jquery to automatically take the user to the 500px downwards. But it has to seem natural.

How can that be done?

6条回答
祖国的老花朵
2楼-- · 2020-08-22 03:35

Is there a lighter version? Just using javascript?

You could consider calling window.location.hash during onload. Have an element with an ID at about 500px down and just do

window.onload = function() {
    window.location.hash = '#foo';
}

Oh, the # is mandatory for IE compatibility ;)

查看更多
Deceive 欺骗
3楼-- · 2020-08-22 03:42

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

查看更多
地球回转人心会变
4楼-- · 2020-08-22 03:43

You can use the jquery scrollto plugin. It's very easy.

http://plugins.jquery.com/scrollTo/

查看更多
神经病院院长
5楼-- · 2020-08-22 03:43
$().scrollTop(500);
查看更多
时光不老,我们不散
6楼-- · 2020-08-22 03:50

Just Javascript: window.scrollBy(0,500);

查看更多
欢心
7楼-- · 2020-08-22 04:00

use the jquery one Jourkey suggested. Cross platform easy to use etc. There is pure JavaScript one you can try, though YMMV on browsers other than IE

"scrollTo Method

Scrolls the window to the specified x- and y-offset. "

http://msdn.microsoft.com/en-us/library/ms536731(VS.85).aspx

查看更多
登录 后发表回答