Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 );
return false;
// [...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.