Skip to content

Instantly share code, notes, and snippets.

@couchoud
Created July 15, 2014 23:11
Show Gist options
  • Save couchoud/d0637838121705b9ae1b to your computer and use it in GitHub Desktop.
Save couchoud/d0637838121705b9ae1b to your computer and use it in GitHub Desktop.
fastClick : function ( event ) {
var target = $(event.currentTarget);
if(event.type === 'touchstart') {
var startX=0, startY=0;
if(event.originalEvent && event.originalEvent.touches) {
startX = event.originalEvent.touches[0].clientX;
startY = event.originalEvent.touches[0].clientY;
}
target.data('startX', startX);
target.data('startY', startY);
target.one('touchend', function( e ) {
target.off('touchmove')
.trigger('click');
e.preventDefault();
return false;
})
.on('touchmove', function( e ) {
var endX=0, endY=0;
if(e.originalEvent && e.originalEvent.touches) {
endX = e.originalEvent.touches[0].clientX;
endY = e.originalEvent.touches[0].clientY;
}
if (Math.abs(endX - $(this).data('startX')) > 10 ||
Math.abs(endY - $(this).data('startY')) > 10) {
e.preventDefault();
target.off('touchend touchmove');
}
});
}
return false;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment