Skip to content

Instantly share code, notes, and snippets.

@AkatQuas
Created August 17, 2019 03:02
Show Gist options
  • Save AkatQuas/e4c19032e4b09d0fe626a3d73d773e21 to your computer and use it in GitHub Desktop.
Save AkatQuas/e4c19032e4b09d0fe626a3d73d773e21 to your computer and use it in GitHub Desktop.
mute the body scrolling when modal is poped
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