Created
October 17, 2013 06:07
-
-
Save erikccoder/7019784 to your computer and use it in GitHub Desktop.
disable touch scrolling bubbling up DOM
This file contains hidden or 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
| //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