Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll to the top of the page using JavaScript?

How do I scroll to the top of the page using JavaScript? The scrollbar instantly jumping to the top of the page is desirable too as I'm not looking to achieve smooth scrolling.

like image 928
KingNestor Avatar asked Jul 17 '09 17:07

KingNestor


People also ask

How do I make my page scrollTo the top in HTML?

window. scrollTo(0, 0); …is a sure bet to scroll the window (or any other element) back to the top.

What is scroll top in JS?

The Element. scrollTop property gets or sets the number of pixels that an element's content is scrolled vertically. An element's scrollTop value is a measurement of the distance from the element's top to its topmost visible content.

How do I scrollTo the top of a page in Chrome?

Move to top or bottom To jump to the bottom of a page, hit Command-down arrow. You can then return to the top of the page with Command-up arrow. On Windows, hit the Home and End keys to go to the top and bottom of a page, respectively.


1 Answers

If you don't need the change to animate then you don't need to use any special plugins - I'd just use the native JavaScript window.scrollTo() method -- passing in 0, 0 will scroll the page to the top left instantly.

window.scrollTo(xCoord, yCoord); 

Parameters

  • xCoord is the pixel along the horizontal axis.
  • yCoord is the pixel along the vertical axis.
like image 142
SavoryBytes Avatar answered Oct 26 '22 02:10

SavoryBytes