Skip to content

Instantly share code, notes, and snippets.

@timhettler
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timhettler/2f13def08158278fe436 to your computer and use it in GitHub Desktop.
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.
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