Categories
JavaScript Answers

How to fix JavaScript scrollTo method doing nothing?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.