Created
September 8, 2023 16:25
-
-
Save jrc03c/74e8fdedd3cff81283e9cef6080f1c91 to your computer and use it in GitHub Desktop.
Temporarily disable page scrolling when modal or menu is open
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let scrollY = 0 | |
// to disable scrolling: | |
scrollY = window.scrollY | |
document.body.style.position = "fixed" | |
document.body.style.top = `-${scrollY}px` | |
// to enable scrolling again: | |
document.body.style.position = "" | |
document.body.style.top = "" | |
window.scrollTo(0, parseInt(scrollY || 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment