I am trying to show some images on a page where they should be shown in grayscale, except on mouse hover when they smoothly transition into color. I\'ve ma
It's really simple, actually:
I tried using the javascript fallback, but it really made no sense, and it was really slow on large images. This made a lot more sense. Note that there is a new syntax for grayscale
, and I had to manually edit the resulting minified CSS from LESS.
Here's my mixin:
.filter (...) {
-webkit-filter: @arguments;
-moz-filter: @arguments;
-ms-filter: @arguments;
-o-filter: @arguments;
filter: @arguments;
}
And my class:
.grayscale-hover, .home-image {
filter: url("data:image/svg+xml;utf8,#grayscale"); /* Firefox 10+, Firefox on Android see http://jsfiddle.net/KDtAX/487/*/
.filter(grayscale(1) blur(1px));
filter: gray; /* IE6-9 */
-webkit-backface-visibility: hidden; /* Fix for transition flickering */
&:hover {
.filter(none);
filter: url("data:image/svg+xml;utf8,#grayscale");
}
}
Works and tested in IE 6+, Firefox, Chrome.