David Wells

Full Stack Developer

Serverless Architectures
User Experience & Product

Serverless, User Experience & Product

Disable Scrolling with JavaScript

Published on Edit this post

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 disable scroll
window.removeEventListener('scroll', noscroll);