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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *