How to automatically scroll to a certain height when loading a page

I want to automatically scroll to 120 pixels when loading a page, please help.

I am new to Javascript and jQuery, so please use plain javascript or jQuery (and PS I know the last name is "function" in javascript).

THANKS.

+7
jquery
source share
4 answers

Here demo

Code $("html, body").animate({ scrollTop: 1000 }, 2000);

+8
source share
 $("body").animate({ scrollTop: 120 }, "slow"); 

Working demo

Make sure you write the above line in the document.ready() function

+6
source share

JavaScript approach

Demo sᴜʀᴇsʜ ᴀᴛᴛᴀ

 document.body.scrollTop = 1000; 
+5
source share

If you scroll a specific element with id element-id , you can use this:

 document.getElementById("element-id").scrollIntoView(); 
+1
source share

All Articles