Created
November 14, 2012 11:31
-
-
Save timwhitlock/4071645 to your computer and use it in GitHub Desktop.
Snippet showing cancelling of touchmove event on vertical swipe
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
// [...] already calculated xmove and ymove since last movement ... ] | |
if( ymove && Math.abs(ymove) > Math.abs(xmove) ){ | |
// this was intended as a vertical scroll - probably of the page | |
// we will allow this event through so the OS/browser can handle it. | |
return true; | |
} | |
if( xmove ){ | |
// else take control of horizonal scroll position and cancel event | |
element.scrollLeft = Math.max( 0, xstart + xmove ); | |
} | |
event.preventDefault(); | |
return false; | |
// [...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment