Created
October 11, 2011 12:58
-
-
Save sindresorhus/1278008 to your computer and use it in GitHub Desktop.
jQuery plugin - Adds a .hover class on click on touch devices. Which will make it easier to use :hover and still support touch devices.
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
$.fn.touchHover = function() { | |
return 'ontouchstart' in document.documentElement ? this.click(function() { | |
$(this).toggleClass('hover'); | |
}) : this; | |
}; | |
/* | |
Example: $('.button').touchHover(); | |
You also need to add .hover to your :hover CSS rules: | |
.button:hover -> .button:hover, .button.hover | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment