Created
June 23, 2016 15:26
-
-
Save swannknani/eca799795860cff222f70b8675f8c8d8 to your computer and use it in GitHub Desktop.
iOS: disable bounce scroll but allow normal scrolling
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 content = document.getElementsById('scrollDiv'); | |
content.addEventListener('touchstart', function (event) { | |
this.allowUp = (this.scrollTop > 0); | |
this.allowDown = (this.scrollTop < this.scrollHeight - this.clientHeight); | |
this.slideBeginY = event.pageY; | |
}); | |
content.addEventListener('touchmove', function (event) { | |
var up = (event.pageY > this.slideBeginY); | |
var down = (event.pageY < this.slideBeginY); | |
this.slideBeginY = 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