Skip to content

Instantly share code, notes, and snippets.

@timhettler
Last active December 17, 2015 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timhettler/5543233 to your computer and use it in GitHub Desktop.
Save timhettler/5543233 to your computer and use it in GitHub Desktop.
A quick way to use the appropriate event based on input device
var interactionType = {
click: (Modernizr.touch) ? 'touchend' : 'click',
down: (Modernizr.touch) ? 'touchstart' : 'mousedown',
up: (Modernizr.touch) ? 'touchend' : 'mouseup',
enter: (Modernizr.touch) ? 'touchstart' : 'mouseenter',
leave: (Modernizr.touch) ? 'touchend' : 'mouseleave',
over: (Modernizr.touch) ? 'touchstart' : 'mouseover',
out: (Modernizr.touch) ? 'touchend' : 'mouseout',
move: (Modernizr.touch) ? 'touchmove' : 'mousemove'
};
$(button).on(interactionType.click, function(){
//do the thing
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment