Created
August 17, 2019 03:02
-
-
Save AkatQuas/e4c19032e4b09d0fe626a3d73d773e21 to your computer and use it in GitHub Desktop.
mute the body scrolling when modal is poped
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 nowTop = 0; | |
const bodyEl = document.body; | |
export default mute => { | |
if (mute) { | |
nowTop = window.scrollY; | |
bodyEl.style.position = 'fixed'; | |
bodyEl.style.top = -nowTop + 'px'; | |
} else { | |
bodyEl.style.position = ''; | |
bodyEl.style.top = ''; | |
window.scrollTo(0, nowTop); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment