To scroll to a specific position in the browser window, you can use the scrollTo() method in the global window object in JavaScript.
For example, to scroll 100px from the top of the page, you can pass 0 as the first argument (X Coordinate) and 100 as the second argument (Y Coordinate)to the scrollTo() method like this,
// Scroll 100px from top of the page 🌟
window.scrollTo(0, 100);
The scrollTo() method accepts 2 arguments:
- The first argument is the
X Coordinateto scroll. - The second argument is the
Y Coordinateto scroll.
See this example live in JSBin.