Last active
August 29, 2015 14:06
-
-
Save timhettler/2f13def08158278fe436 to your computer and use it in GitHub Desktop.
Function to disable scrolling on a webpage, with optional override. Most often used with mobile web apps.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isTouchAllowed = function (target) { | |
while (target !== document.body) { | |
if (target.getAttribute('allow-touch') !== undefined) { | |
return true; | |
} | |
target = target.parentNode(); | |
} | |
return false; | |
}; | |
document.body.bind('touchmove', function (e) { | |
if(!isTouchAllowed(e.target)) { | |
e.preventDefault(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment