Create a gist now

Instantly share code, notes, and snippets.

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