How to stop scrolling child div from scrolling the window with JavaScript?

Spread the love

To stop scrolling child div from scrolling the window with JavaScript, we set the overflow property dynamically.

For instance, we write

<div
  onmouseover="document.body.style.overflow = 'hidden';"
  onmouseout="document.body.style.overflow = 'auto';"
></div>

to set the onmouseover property to set the document.body.style.overflow property to 'hidden' when we move our mouse into the div.

And we set the document.body.style.overflow property to 'auto' when we move our mouse away from the div.

Leave a Reply

Your email address will not be published.