Categories
JavaScript Answers

How to fix scrollIntoView() causing the whole page to move with JavaScript?

Spread the love

Sometimes, we want to fix scrollIntoView() causing the whole page to move with JavaScript.

In this article, we’ll look at how to fix scrollIntoView() causing the whole page to move with JavaScript.

How to fix scrollIntoView() causing the whole page to move with JavaScript?

To fix scrollIntoView() causing the whole page to move with JavaScript, we can call scrollIntoView with a few options.

For instance, we write

element.scrollIntoView({
  behavior: "smooth",
  block: "nearest",
  inline: "start",
});

to call scrollIntoView with an object that jumps to the nearest block element with block set to 'nearest'.

And we jump to the start of the inline element with inline set to 'start'.

Conclusion

To fix scrollIntoView() causing the whole page to move with JavaScript, we can call scrollIntoView with a few options.

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 *