Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable all scrolling on webpage

I would like to know if it is possible to disable all scrolling on a webpage.

I am currently using

html, body { overflow:hidden; }

The issue is that this does not work on iOS devices and if you hold in the mouse wheel and drag it down you can also scroll, so it seems like a very poor solution to the problem

Is there a way to disable all methods of scrolling on all devices and then re-enable it?

like image 704
Robert E. McIntosh Avatar asked Jul 11 '13 15:07

Robert E. McIntosh


People also ask

How do I turn off touch screen scrolling?

Once you have Device Manager open, scroll down and expand the “Human Interface Devices” menu. Then scroll down and right-click on HID-Compliant touch screen and select Disable device from the menu. After that, you'll need to verify you want to turn the feature off by clicking Yes in the dialog box that pops up.


1 Answers

I have had this exact same issue, i fixed it with the following;

var disableScroll = false;
var scrollPos = 0;
function stopScroll() {
    disableScroll = true;
    scrollPos = $(window).scrollTop();
}
function enableScroll() {
    disableScroll = false;
}
$(function(){
    $(window).bind('scroll', function(){
         if(disableScroll) $(window).scrollTop(scrollPos);
    });
    $(window).bind('touchmove', function(){
         $(window).trigger('scroll');
    });
});

the touch move is bound to the window as the window scroll event is not fired until touch move is completed, so this allows a much smoother experience on iOS!

This isn't a perfect solution as you can 'throw' the page, but it will return to desired position when the throw has complete (as the window scroll event will then be fired). This is because iOS browsers strip out a lot of events for performance. also setTimeout and setInterval functions do not fire whilst the page is being thrown, having a loop isn't an option either!

see here http://jsfiddle.net/8T26k/

like image 104
rorypicko Avatar answered Oct 10 '22 20:10

rorypicko