Skip to content

Instantly share code, notes, and snippets.

@tfsojon
Created May 10, 2023 07:51
Show Gist options
  • Save tfsojon/b00d7fb8b83e5be2b33e3c978a8bf683 to your computer and use it in GitHub Desktop.
Save tfsojon/b00d7fb8b83e5be2b33e3c978a8bf683 to your computer and use it in GitHub Desktop.
const disableBodyScroll = () => {
const documentWidth = document.documentElement.clientWidth;
const scrollbarWidth = Math.abs(window.innerWidth - documentWidth);
body.style.overflowY = 'hidden';
body.style.paddingRight = scrollbarWidth + "px";
}
const enableBodyScroll = () => {
setTimeout(() => {
body.style.overflowY = '';
body.style.paddingRight = '';
}, 200);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment