Skip to content

Instantly share code, notes, and snippets.

@jbuncle
Created May 19, 2016 12:23
Show Gist options
  • Save jbuncle/9bc6a64962e133bdc37698f4d8769d26 to your computer and use it in GitHub Desktop.
Save jbuncle/9bc6a64962e133bdc37698f4d8769d26 to your computer and use it in GitHub Desktop.
Simple jQuery Plugin which fades out an elements siblings on hover.
/*!
* Simple jQuery Plugin which fades out an elements siblings on hover.
*
* Copyright 2016 James Buncle
*
* Released under the MIT license.
* http://jquery.org/license
*
*/
(function ($) {
$.fn.siblingFader = function () {
var $selection = $(this);
return this.each(function () {
var $hovered = $(this);
var $siblings = $selection.not($hovered);
$(this).hover(function (event) {
$hovered.stop().animate({
opacity: 1
});
$siblings.stop().animate({
opacity: 0.5
});
}, function (event) {
$siblings.stop().animate({
opacity: 1
});
$hovered.stop().animate({
opacity: 1
});
});
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment