0

When I click on the button, I show a pop-up on the right and I do body {overflow: hide;} to prevent page scrolling. When closing the pop-up, I do body {overflow: auto}. I have a window size changing and it's not good.

Tell me how to properly enable and disable the scroll without changing the window size?

Vladislav
  • 476
  • 2
  • 13

1 Answers1

0

Disable scroll:

document.body.style.paddingRight = `${window.innerWidth - document.body.offsetWidth}px`
document.body.style.overflowY = 'hidden'

Enable scroll:

document.body.style.paddingRight = '0px'
document.body.style.overflowY = 'auto'
Vladislav
  • 476
  • 2
  • 13
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Ethan Jun 11 '22 at 14:14