How to disable, enable, then disable again scrolling in ipad/iphone with e.preventDefault();?

16,934

You could create a toggle instead, where your doTouchMove() function switches between false and true every time it's called:

(function () { // Set up a closure so we don't pollute the global scope
    var state = false;
    function doTouchMove() {
        state = !state;
    }
    document.ontouchmove = function(e){
        return state;
    }
    document.getElementById("myDoubleClickElement").ondblclick = doTouchMove;
})();

Now, every time you double-click #myDoubleClickElement, it will toggle the state variable's value between false and true, effectively disabling on the even clicks and enabling on the odd clicks.

Share:
16,934
cat
Author by

cat

Updated on August 02, 2022

Comments

  • cat
    cat almost 2 years

    I have it disabled already, and I can enable it again. I used:

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

    In the document.ready(); to disable it.

    And I used this to enable it.

    function doTouchMove(state) {
        document.ontouchmove = function(e){
          return state;
        }
    }
    

    I have it so when a user double clicks on an element, the doTouchMove is called. But how do I make it disabled again?

    Thanks