Created
October 14, 2011 10:17
-
-
Save tlync/1286743 to your computer and use it in GitHub Desktop.
tap for xui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var hasTouch = 'ontouchstart' in window; | |
x$.extend({ | |
tap: function(fn, delay){ | |
// browser fallback | |
if(!hasTouch){ | |
return this.each(function(){ | |
x$(this).click(fn); | |
}); | |
} | |
delay = delay || 50; | |
var moveAmount = 10; | |
return this.each(function(){ | |
var start = 0, | |
x = null, | |
y = null; | |
x$(this).touchstart(function(e){ | |
start = e.timeStamp; | |
var t = e.touches[0]; | |
x = t.screenX; | |
y = t.screenY; | |
e.preventDefault(); | |
}).touchend(function(e){ | |
var t = e.changedTouches[0]; | |
if((Math.abs(t.screenX - x) <= moveAmount && Math.abs(t.screenY - y) <= moveAmount) || | |
e.timeStamp - start < delay){ | |
fn.apply(this); | |
} | |
x = null; | |
y = null; | |
}); | |
}); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment