简体   繁体   English

CSS转换背景图片网址失败

[英]CSS transition fails for background-image url

Following examples found on Fade Effect on Link Hover? 以下示例在“链接悬停”上的“ 淡入淡出效果”中找到

I made this: http://jsfiddle.net/felipelalli/ns9d1vug/ 我做了这个: http : //jsfiddle.net/felipelalli/ns9d1vug/

<div class="fade"/>

.fade {
-o-transition: 0.3s;
-moz-transition: 0.3s;
-khtml-transition: 0.3s;
-webkit-transition: 0.3s;
-ms-transition: 0.3s;
transition: 0.3s;

 width:128px;height:128px;
background:url('http://nuclearpixel.com/content/icons/2010-02-09_stellar_icons_from_space_from_2005/earth_128.png')
}

.fade:hover {
color: #b50000;
    width:128px;height:128px;
 background:url('http://upload.wikimedia.org/wikipedia/commons/b/b2/Crystal_128_babelfish.png')
}

Why it works fine in Chrome but not Firefox? 为什么它在Chrome上能正常运行,但在Firefox上却不能运行?

It isn't working in FF, because Firefox does not support transitioning a background image, only background-color. 它在FF中不起作用,因为Firefox不支持转换背景图片,仅支持背景色。 If you want to transition a background image, use two separate <div> : 如果要转换背景图像,请使用两个单独的<div>

 .fade div { -o-transition: 0.3s; -moz-transition: 0.3s; -khtml-transition: 0.3s; -webkit-transition: 0.3s; -ms-transition: 0.3s; transition: 0.3s; width:128px; height:128px; position:absolute; top:0; left:0; } .fade{ position:relative; width:128px; height:128px; } .backone{ z-index:1; background:url('http://nuclearpixel.com/content/icons/2010-02-09_stellar_icons_from_space_from_2005/earth_128.png'); } .backtwo{ background:url('http://upload.wikimedia.org/wikipedia/commons/b/b2/Crystal_128_babelfish.png'); opacity:0; z-index:5; } .fade:hover .backtwo{ opacity:1; } .fade:hover .backone{ opacity:0; } 
 <div class="fade"> <div class="backone"></div> <div class="backtwo"></div> </div> 

You should use two different elements, and fade between them, instead of changing the background image for one element. 您应该使用两个不同的元素,然后在它们之间淡入淡出,而不是更改一个元素的背景图像。

This guys has made an example: http://css3.bradshawenterprises.com/cfimg/ 这些家伙举了一个例子: http : //css3.bradshawenterprises.com/cfimg/

I don't think you should be able to do this, but apparently Chrome is just being nice to you... :-) 我认为您不应该能够做到这一点,但显然Chrome只是对您很好... :-)

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

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