javascript disable scroll code example

Example 1: javascript disable right click

document.addEventListener('contextmenu', event => event.preventDefault());

Example 2: javascript disable scrolling on body

document.body.style.overflow = 'hidden';

Example 3: javascript disable scrolling

function disableScrolling(){
    var x=window.scrollX;
    var y=window.scrollY;
    window.onscroll=function(){window.scrollTo(x, y);};
}

function enableScrolling(){
    window.onscroll=function(){};
}

Example 4: javascript cancel scroll

const pause = (scroll) => window.clearTimeout(scroll)

Tags:

Css Example