Skip to content

Instantly share code, notes, and snippets.

@mandelbro
Last active October 5, 2015 00:28
Show Gist options
  • Save mandelbro/2723479 to your computer and use it in GitHub Desktop.
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
/**
* 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