Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. But it has to seem natural.

How can that be done?

like image 812
TIMEX Avatar asked Nov 20 '09 22:11

TIMEX


4 Answers

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

like image 135
luvieere Avatar answered Oct 07 '22 05:10

luvieere


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

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

like image 45
Jourkey Avatar answered Oct 07 '22 04:10

Jourkey


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 ;)

like image 37
BalusC Avatar answered Oct 07 '22 06:10

BalusC


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

like image 32
Byron Whitlock Avatar answered Oct 07 '22 04:10

Byron Whitlock