2

I have disabled scrolling on the iPad using:

function disableScrolling() {
    document.ontouchmove = function(e){
            e.preventDefault();
    }
}

Is there a way to simply enable it again?

It would be especially helpful in a function like:

function enableScrolling() {
    // enable scrolling
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
shrewdbeans
  • 11,971
  • 23
  • 69
  • 115

1 Answers1

10

This should work,

var disableScroll = false;

function disableScrolling() {
    disableScroll = true;
}


function enableScrolling() {
    disableScroll = false;
}

document.ontouchmove = function(e){
   if(disableScroll){
     e.preventDefault();
   } 
}
Jashwant
  • 28,410
  • 16
  • 70
  • 105
  • 3
    This works brilliantly! I combined it with [this](http://stackoverflow.com/a/3656618/1359306) answer to disable/enable on both touch devices and desktop browsers. – Patrick Jan 28 '13 at 10:53
  • This is perfect! Nice and clean. Thank you. – Staysee Apr 19 '15 at 01:59