Skip to content

Instantly share code, notes, and snippets.

@kovtunos
Last active February 7, 2017 20:05
Show Gist options
  • Select an option

  • Save kovtunos/c15dfad8a676625f777d716797f56265 to your computer and use it in GitHub Desktop.

Select an option

Save kovtunos/c15dfad8a676625f777d716797f56265 to your computer and use it in GitHub Desktop.
Grayscale image with color hover #css #js
// CSS
.grayscale {
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */
filter: gray; /* IE6-9 */
-webkit-filter: grayscale(100%); /* Chrome 19+, Safari 6+, Safari 6+ iOS */
}
// JS
$('.image-list img').addClass('grayscale');
$('.image-list a').hover(function() {
$(this).children('img').removeClass('grayscale');
}, function() {
$(this).children('img').addClass('grayscale');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment