Question: How to scroll to the top of the page using javascript
Answer:
You can see a live demo of this concept on our website, as we have also integrated 'Back to Top Button' on our website. Also, we have published a separate article on "Back to a top button using jquery", you can read that article. But in this article, we are using JavaScript to create a 'Back to top of the page' animation with a smooth experience.
First: the simplest code of 'back to the top of the page'. But these codes don't provide smooth scrolling.
window.scrollTo(0, 0);
Second: This code is also simple but these codes provide smooth scrolling.
window.scroll({ top: 0, left: 0, behavior: 'smooth' });
We try to provide you the best content, if there is any mistake in this article or there is any mistake in code, then let us know.
Comments
Post a Comment