Pointer events on click, but not on scroll

Is it possible to allow clicks but not scroll events?

pointer-events: none; 

Disable both types of inputs, I would like to disable only scrolling. Any other ideas for workarounds?

+6
source share
2 answers

Do it with javascript:

 function noScroll(event) { event = event || window.event; if (event.preventDefault) { event.preventDefault(); } event.returnValue = false; return false; } // disable scolling on the whole window: if (!window.addEventListener) { // old IE only window.attachEvent("onscroll", noScroll); } else { // Firefox only window.addEventListener("DOMMouseScroll", noScroll); // anything else window.addEventListener("scroll", noScroll); } // disable scrolling on a single element: var el = document.getElementById("elementID"); if (!el.addEventListener) { el.attachEvent("onscroll", noScroll); } else { el.addEventListener("DOMMouseScroll", noScroll); el.addEventListener("scroll", noScroll); } 

That should do the trick.

+1
source

Add this css:

 .stopScroll{ height:100%; overflow:hidden; } 

Then in jQuery:

 $('body').addClass('stopScroll'); 

Look at the fiddle: https://jsfiddle.net/26dct8o3/1/

It would help if you were looking for this. Otherwise, let me know in the comments if this is not what you want.

+1
source

All Articles