Skip to content

Instantly share code, notes, and snippets.

@erikccoder
Created October 17, 2013 06:07
Show Gist options
  • Select an option

  • Save erikccoder/7019784 to your computer and use it in GitHub Desktop.

Select an option

Save erikccoder/7019784 to your computer and use it in GitHub Desktop.
disable touch scrolling bubbling up DOM
//http://stackoverflow.com/questions/16889447/prevent-full-page-scrolling-ios
elem.addEventListener('touchstart', function(event){
this.allowUp = (this.scrollTop > 0);
this.allowDown = (this.scrollTop < this.scrollHeight - this.clientHeight);
this.prevTop = null; this.prevBot = null;
this.lastY = event.pageY;
});
elem.addEventListener('touchmove', function(event){
var up = (event.pageY > this.lastY), down = !up;
this.lastY = event.pageY;
if ((up && this.allowUp) || (down && this.allowDown)) event.stopPropagation();
else event.preventDefault();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment