Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created March 26, 2012 17:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pamelafox/2207028 to your computer and use it in GitHub Desktop.
Save pamelafox/2207028 to your computer and use it in GitHub Desktop.
Touch Events
dom.each(function() {
$(this).unbind('tap', callback);
$(this).bind('tap', callback);
$(this).bind('touchstart', function(e) {
e.preventDefault();
var item = e.currentTarget;
if (ISTOUCHING) return;
item.moved = false;
ISTOUCHING = true;
item.startX = e.touches[0].pageX;
item.startY = e.touches[0].pageY;
$(item).addClass('active');
});
$(this).bind('touchmove', function(e) {
var item = e.currentTarget;
if (Math.abs(e.touches[0].pageX - item.startX) > 10 ||
Math.abs(e.touches[0].pageY - item.startY) > 10) {
item.moved = true;
$(item).removeClass('active');
}
});
$(this).bind('touchend', function(e) {
var item = e.currentTarget;
ISTOUCHING = false;
if(!item.moved) {
//e.stopPropagation();
//e.preventDefault();
$(item).trigger('tap');
}
setTimeout(function() {
$(item).removeClass('active');
}, 1000);
delete item.moved;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment