Skip to content

Instantly share code, notes, and snippets.

@papucho
Created April 18, 2013 20:59
Show Gist options
  • Save papucho/5416172 to your computer and use it in GitHub Desktop.
Save papucho/5416172 to your computer and use it in GitHub Desktop.
Grayscale filter using SVG+CSS
<img src="http://lorempixel.com/400/200/sports/" alt="" class="fader">
Display the source blob
Display the rendered blob
Raw
<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>
img.fader {
filter: url(filter.svg#grayscale); /* Firefox 3.5+ */
filter: gray; /* IE6-9 */
-webkit-filter: grayscale(1); /* Google Chrome & Safari 6+ */
-webkit-transition: all 2s;
}
img:hover {
filter: none;
-webkit-filter: grayscale(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment