An Interest In:
Web News this Week
- March 5, 2024
- March 4, 2024
- March 3, 2024
- March 2, 2024
- March 1, 2024
- February 29, 2024
- February 28, 2024
December 1, 2021 01:21 pm GMT
Original Link: https://dev.to/chetan_atrawalkar/smooth-scroll-to-top-functionality-using-javascript-easy-way-15m1
Smooth Scroll-To-Top Functionality Using JavaScript [Easy Way].
Halo Guys
In this tutorial we will show you how to add scroll the page to the top smoothly using pure javascript.
Scroll to top buttons allow users to quickly return to the top of a webpage with a single click. This can be very useful when the page has a lot of content.
- Lets start by creating a
scrollToTop()
function that will contain all the required JavaScript:
function scrollToTop(){// all JavaScript will go here};
- Next inside the
scrollToTop()
function pass the window.scrollTo() method with two parameters coordinate and behaviour:
function scrollToTop() {window.scrollTo({ top: 0, behavior: 'smooth'})}
- Next best part is smooth scrolling could be done easily using
behavior:'smooth'
.
Thats all, this is how to smoothly scroll page to top using javascript. You can customize this code further as per your requirement.
Keep Claim And Just Code It
Original Link: https://dev.to/chetan_atrawalkar/smooth-scroll-to-top-functionality-using-javascript-easy-way-15m1
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To