Created
May 29, 2012 12:06
-
-
Save RaVbaker/2828079 to your computer and use it in GitHub Desktop.
hover on iOS testing
This file contains hidden or 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
javascript:(function(){var jsCode=document.createElement('script');jsCode.setAttribute('src','https://raw.github.com/gist/2828079/hover.js');document.body.appendChild(jsCode);}()); |
This file contains hidden or 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
// emulate css `:hover` in JS on iOS devices | |
// works like: | |
// #portal-top #menu_haut ul li:hover ul{ display: block } | |
(function($) { | |
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) { | |
$(function() { | |
var hoverElSelector = "#portal-top #menu_haut > ul > li > a", displayEl = "ul"; | |
$(hoverElSelector).bind('touchstart', function() { | |
$(this).next(displayEl).css('display', 'block'); | |
}); | |
$(hoverElSelector).bind('touchend', function() { | |
$(this).next(displayEl).css('display', ''); | |
}); | |
}); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment