Sunday, January 13, 2019

Scroll to the top of the page using JavaScript?




How do I scroll to the top of the page using a JavaScript? It is desirable even if the scrollbar instantly jumps to the top. I'm not looking for a smooth scrolling.


Answer



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(x-coord, y-coord);


Parameters





  • x-coord is the pixel along the horizontal axis.

  • y-coord is the pixel along the vertical axis.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...