Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Created April 30, 2012 17:31
Show Gist options
  • Save james2doyle/2560306 to your computer and use it in GitHub Desktop.
Save james2doyle/2560306 to your computer and use it in GitHub Desktop.
Touch detection and replacement of event listeners
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