Created
March 9, 2015 14:49
-
-
Save skle/0d817ea2285269db8867 to your computer and use it in GitHub Desktop.
Disable body scroll on iOS, enable scroll on scrollable elements
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
| $(document).on('touchmove',function(e) | |
| { | |
| e.preventDefault(); | |
| }); | |
| $(document).on('touchstart', '.scroller', function(e) | |
| { | |
| this.startScrollY = e.originalEvent.touches[0].screenY; | |
| this.mayScroll = false; | |
| }); | |
| $(document).on('touchmove', '.scroller', function(e) | |
| { | |
| if (this.mayScroll == false) | |
| { | |
| var iDelta = (this.startScrollY - e.originalEvent.touches[0].screenY); | |
| if (this.scrollTop == 0 && iDelta < 0) /* allready on top */ | |
| { | |
| return; | |
| } | |
| else if ((this.scrollTop+this.clientHeight) == this.scrollHeight && iDelta > 0) /* allready on bottom */ | |
| { | |
| return; | |
| } | |
| else | |
| { | |
| this.mayScroll = true; | |
| } | |
| } | |
| e.stopPropagation(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment