Skip to content

Instantly share code, notes, and snippets.

@timwhitlock
Created November 14, 2012 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timwhitlock/4071645 to your computer and use it in GitHub Desktop.
Save timwhitlock/4071645 to your computer and use it in GitHub Desktop.
Snippet showing cancelling of touchmove event on vertical swipe
// [...] 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