Skip to content

Instantly share code, notes, and snippets.

@RaVbaker
Created May 29, 2012 12:06
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 RaVbaker/2828079 to your computer and use it in GitHub Desktop.
Save RaVbaker/2828079 to your computer and use it in GitHub Desktop.
hover on iOS testing
javascript:(function(){var jsCode=document.createElement('script');jsCode.setAttribute('src','https://raw.github.com/gist/2828079/hover.js');document.body.appendChild(jsCode);}());
// 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