Jump to the Page Top with JavaScript
Do you want to effortlessly scroll to the top of any web page, leaving the scrollbar at its peak? JavaScript makes this task a breeze.
One effective method is to utilize the native window.scrollTo() method. By specifying coordinates of 0 for both the horizontal and vertical axes, you can instantly transport the page to the top left corner without any smooth scrolling effects.
The syntax is straightforward:
window.scrollTo(xCoord, yCoord);
Where:
By setting both coordinates to 0, you can achieve the desired instant jump to the page top.
The above is the detailed content of How Can JavaScript Instantly Scroll to the Top of a Web Page?. For more information, please follow other related articles on the PHP Chinese website!