Skip to content

Instantly share code, notes, and snippets.

@lotsofcode
Created October 17, 2012 16:29
Show Gist options
  • Select an option

  • Save lotsofcode/3906542 to your computer and use it in GitHub Desktop.

Select an option

Save lotsofcode/3906542 to your computer and use it in GitHub Desktop.
jQuery fade child element
$.fn.childFader = function(options) {
var settings, defaults;
defaults = {
opacity: .5,
hoverOpacity: 1,
child: 'img'
};
settings = $.extend({}, defaults, options);
return $(this).each(function(options) {
var child = $(settings.child, this);
if (child) {
child.css({opacity: settings.opacity});
$(this).hover(function() {
child.animate({opacity: settings.hoverOpacity});
}, function() {
child.animate({opacity: settings.opacity});
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment