Switching Hover/Touch Events For Desktop/Mobile Devices
The following snippet will switch the classical desktop hover events to touch events.
1 2 3 4 5 6 7 8 9 10 11 |
var isTouchSupported = 'ontouchstart' in window; var startEvent = isTouchSupported ? 'touchstart' : 'mouseenter'; var endEvent = isTouchSupported ? 'touchend' : 'mouseleave'; $('.yourclass').on(startEvent,function(){ doSomething(this); }); $('.yourclass').on(endEvent,function(){ doSomething(this); }); |
Snippet Source/Credit: