Disable Scrolling with JavaScript

Handy for modals and other cases where you don’t want the user to be able to scroll

function noScroll() {
  window.scrollTo(0, 0);
}

// add listener to disable scroll
window.addEventListener('scroll', noScroll);

// Remove listener to re-enable scroll
window.removeEventListener('scroll', noScroll);