Skip to content

Instantly share code, notes, and snippets.

@iamravenous
Last active March 3, 2021 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamravenous/5744e8a580fb0b22838d to your computer and use it in GitHub Desktop.
Save iamravenous/5744e8a580fb0b22838d to your computer and use it in GitHub Desktop.
Highlight element on hover and fade all the same elements, except the current
/*
* Highlight Element
* Highlight element on hover and fade all the same elements, except the current
* Recommended for use in galleries or in grids with many items or cards
* Author: Franco Moya - @iamravenous
*/
var highlight = $('.grid-item');
highlight.hover (
/* On mouse enter */
function() {
/* Highlight on hover */
$(this).css('opacity', '1');
/* Fade all the same elements, except the current */
highlight.not(this).css('opacity', '.3');
}, function() {
/* Restores all items on mouse leave */
highlight.css('opacity', '1');
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment