Skip to content

Instantly share code, notes, and snippets.

@mizanRahman
Created February 12, 2013 13:34
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 mizanRahman/4769918 to your computer and use it in GitHub Desktop.
Save mizanRahman/4769918 to your computer and use it in GitHub Desktop.
Cross browser CSS3 image gray-scale and colorize on hover.
body{
padding: 50px 10px;
}
img{
border: 10px solid #ccc;
box-shadow: 0px 0px 1px #555;
}
img.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%);
}
<div><a href="http://www.flickr.com/photos/thecrowleys/8464961316/" title="Forth Road bridge by SparklyOne, on Flickr"><img class="grayscale" src="http://farm9.staticflickr.com/8380/8464961316_bff336e8b1.jpg" width="480" height="246" alt="Forth Road bridge"></a></div>
$('img').hover(function(){
$(this).toggleClass("grayscale")
//alert('hello');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment