Created
April 30, 2012 17:31
-
-
Save james2doyle/2560306 to your computer and use it in GitHub Desktop.
Touch detection and replacement of event listeners
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
var isTouch = function() { | |
return !!('ontouchstart' in window) ? true : false; | |
} | |
if(isTouch()) { | |
var fireEvent = ['touchstart','touchend']; | |
} else { | |
var fireEvent = ['mousedown','mouseup']; | |
} | |
elem.addEventListener(fireEvent[0],function(){ | |
// do some stuff | |
},false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment