Created
April 24, 2019 02:15
-
-
Save timc1/d92698c7317c3d01a9612b062c3fecb1 to your computer and use it in GitHub Desktop.
Prevent overflow scrolling — nice to use when displaying a modal
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
const capturePosition = () => { | |
const cachedPosition = window.pageYOffset | |
return { | |
freeze: () => { | |
document.body.style = | |
`position: fixed; | |
top: ${cachedPosition * -1}px; | |
width: 100%;` | |
}, | |
unfreeze: () => { | |
document.body.removeAttribute('style') | |
window.scrollTo({ | |
top: cachedPosition, | |
}) | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: