Sometimes, we want to fix JavaScript scrollTo method doing nothing.
In this article, we’ll look at how to fix JavaScript scrollTo method doing nothing.
How to fix JavaScript scrollTo method doing nothing?
To fix JavaScript scrollTo method doing nothing, we put it in a setTimeout
callback.
For instance, we write
setTimeout(() => {
window.scrollTo(0, 300);
}, 2);
to call window.scrollTo
in the setTimeout
callback to delay the scrolling.
Conclusion
To fix JavaScript scrollTo method doing nothing, we put it in a setTimeout
callback.