简体   繁体   English

灰度到颜色过渡在Firefox中不起作用

[英]Grayscale to color transition not working in firefox

.picture-box img { .picture-box img {

display: inline-block;
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 3.5+ */
filter: gray; /* IE6-9 */
filter: grayscale(100%);
-webkit-filter: grayscale(1);
-moz-filter: grayscale(1);
-o-filter: grayscale(1);
-ms-filter: grayscale(1);

} }

.picture-box img:hover { .picture-box img:hover {

filter: none; /* IE6-9 */
filter: grayscale(0);
-webkit-filter: grayscale(0);
-moz-filter: grayscale(0);
-o-filter: grayscale(0);
-ms-filter: grayscale(0);

-webkit-transition: all 2.0s ease-out;
-moz-transition: all 2.0s ease-out;
-ms-transition: all 2.0s ease-out;
-o-transition: all 2.0s ease-out;
transition: all 2.0s ease-out;

} }

What is wrong with this code? 此代码有什么问题? Transition does not work in Firefox. 过渡在Firefox中不起作用。 I have 21.0 installed. 我已经安装了21.0。

Try setting .picture-box img:hover to this: 尝试将.picture-box img:hover设置为此:

 filter:grayscale(0%); 
 -webkit-filter: grayscale(0%);
 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");

You can look it up here. 您可以在这里查找。 http://www.cheesetoast.co.uk/add-grayscale-images-hover-css-black-white/ http://www.cheesetoast.co.uk/add-grayscale-images-hover-css-black-white/

The problem is that Firefox does not yet support CSS filter effects (as of 29.0.1), which is why your first block of code includes a line for an SVG filter, which Firefox does support. 问题是Firefox尚不支持CSS过滤器效果(自29.0.1开始),这就是为什么您的第一段代码包含Firefox支持的SVG过滤器行的原因。 Unlike CSS filter effects, the SVG filter cannot be transitioned with CSS. 与CSS滤镜效果不同,SVG滤镜无法通过CSS转换。

I don't know of any pure CSS solution for Firefox, but there are a few ways to tackle it with JS (such as dynamically replacing the image with a SVG or HTML5 canvas copy that can be overlaid and faded). 我不知道用于Firefox的任何纯CSS解决方案,但是有几种方法可以使用JS解决它(例如用可以叠加和淡入淡出的SVG或HTML5画布副本动态替换图片)。 This jQuery plugin does a good job of covering all the bases for most browsers: https://github.com/karlhorky/gray 这个jQuery插件很好地涵盖了大多数浏览器的所有基础: https : //github.com/karlhorky/gray

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM