Achieve Instant Jump Scrolling to Page Top with JavaScript
If you're striving for an immediate jump to the top of the page when scrolling, without any graceful transitions, JavaScript offers a straightforward solution.
Method:
To instantly scroll to the top of the page using JavaScript, leverage the window.scrollTo() method. This method takes two parameters:
Example:
The following JavaScript code will instantly scroll the page to the top:
window.scrollTo(0, 0);
This code will skip the smooth scrolling animation and jump to the top of the page immediately. It's a simple yet effective way to implement instant top-of-page scrolling in your web project.
The above is the detailed content of How Can I Instantly Jump to the Top of a Page Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!