/ Published in: JavaScript
Hover events can be irrelevant on mobile devices relying on touch events.
This script switches the classical desktop hover events to touch events.
Inspired by: http://jbkflex.wordpress.com/2012/07/12/javascript-touch-event-or-mouse-event-detect-and-handle-according-to-device/
This script switches the classical desktop hover events to touch events.
Inspired by: http://jbkflex.wordpress.com/2012/07/12/javascript-touch-event-or-mouse-event-detect-and-handle-according-to-device/
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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); });