Last active
December 17, 2015 03:28
-
-
Save timhettler/5543233 to your computer and use it in GitHub Desktop.
A quick way to use the appropriate event based on input device
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 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