Last active
October 5, 2015 00:28
-
-
Save mandelbro/2723479 to your computer and use it in GitHub Desktop.
simple jQuery plugin to enable the hover state on non-standard elements, I mostly use it for adding a hover state to li elements in menus
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
/** | |
* hoverEnabler | |
* @mandelbro 05/16/2012 | |
* | |
* A simple solution to adding css hover effects to elements | |
* in a cross browser capatable way | |
* | |
* Just add the .hoverEnabler class to any element which lacks | |
* cross-browser support for the :hover css psuedo class, then | |
* instead of using the pseudo class, just use the .hover class | |
* | |
* Requires jQuery ... obviously | |
*/ | |
(function($) { | |
$.fn.enableHover = function() { | |
this.hover( | |
function(event) { // mouse enter | |
$(this).addClass('hover'); | |
}, | |
function(event) { // mouse leave | |
$(this).removeClass('hover'); | |
} | |
); | |
}; | |
function hoverEnabler() { | |
// get all hoverable div elements | |
var elements = $('.hoverEnabler'); | |
// for each, add a hover listener | |
$.each(function() { | |
$(this).removeClass('hoverEnabler').enableHover(); | |
}); | |
} | |
$(hoverEnabler); | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment