Skip to content

Instantly share code, notes, and snippets.

@annelyse
Created August 4, 2021 14:07
Show Gist options
  • Save annelyse/192edd1f6636dbd92bbfa8168018b430 to your computer and use it in GitHub Desktop.
Save annelyse/192edd1f6636dbd92bbfa8168018b430 to your computer and use it in GitHub Desktop.
//thanks to : https://css-tricks.com/prevent-page-scrolling-when-a-modal-is-open/
if ($(this).parent().hasClass('open-menu') == true) {
const scrollY = document.body.style.top;
document.body.style.position = '';
document.body.style.top = '';
window.scrollTo(0, parseInt(scrollY || '0') * -1);
} else {
document.body.style.top = '-' + window.scrollY + 'px';
document.body.style.position = 'fixed';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment