我正在图像上使用去饱和度使其变成黑白。我希望它在悬停时淡出颜色(使用 CSS3 过渡),但我似乎无法让它工作。有什么想法吗?
这是一个例子:http://jsfiddle.net/sChY5/下面是我的 CSS
img.desaturate {
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
filter: grayscale(100%);
-webkit-filter: grayscale(100%); -moz-filter: grayscale(100%);
-ms-filter: grayscale(100%); -o-filter: grayscale(100%);
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');
filter: gray;
-webkit-filter: grayscale(1);
}
img.desaturate:hover {
filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'1 0 0 0 0, 0 1 0 0 0, 0 0 1 0 0, 0 0 0 1 0\'/></filter></svg>#grayscale");
-webkit-filter: grayscale(0%);
}
最佳答案
您没有将 transition
属性放在 good 类选择器上。
不得在 img.desaturate:hover
上,但在 img.desaturate
上
(我说的是您的 jsfiddle 演示,它与您在此处发布的代码不同)
关于CSS3 动画去饱和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14771854/