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:
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:
Add a smart 'back to top' button to your website 👓🔝
Rob OLeary ・ Apr 27 ・ 9 min read