DEV Community

Discussion on: How to create a scroll to top button with vanilla JS & CSS

Collapse
 
robole profile image
Rob OLeary

To improve the performance, you can consider debouncing the scroll handler also.

In your code, the handler function is called every time the user scrolls the page by a few pixels. This could mean the handler function is called many times per second if you scroll quickly through the page, which is not necessary.

I speak about using debouncing in the following post, if you would like to learn more: