0

我正在玩带有 CSS3 过渡的图像交换悬停效果。不幸的是,它只适用于 Chrome。我已经从 CSS3 过渡中看到了很多示例,它们在 Chrome、Firefox 和 Safari 中都可以完美运行,但这次不是...... :( 问题出在哪里?

http://jsfiddle.net/kYZ9Y/

.logo {
float: left;
z-index: 1;
width: 325px;
height: 73px;
background: url(../img/logo.png) no-repeat;
position: absolute;
-moz-transition: all .4s ease;
-webkit-transition: all .4s ease;
-ms-transition: all .4s ease;
-o-transition: all .4s ease;
transition: all .4s ease;
}

.logo:hover {
z-index: 2;
opacity: 1;
background: url(../img/logo1.png) no-repeat;
}

干杯!

4

3 回答 3

1

只需像这样将轻松更改为轻松进出

-moz-transition: all .4s ease-in-out;
    -webkit-transition: all .4s ease-in-out;
    -ms-transition: all .4s ease-in-out;
    -o-transition: all .4s ease-in-out;
    transition: all .4s ease-in-out;

演示:http: //jsfiddle.net/kYZ9Y/4/

更多缓动功能请访问http://easings.net/

标记:

<div class="logo"></div>

样式 :

.logo {
    float: left;
    z-index: 1;
    width: 300px;
    height: 225px;
    background: url(http://pixellab-design.com/img/1.jpg) no-repeat;
    position: absolute;
    -moz-transition: all .4s ease-in-out;
    -webkit-transition: all .4s ease-in-out;
    -ms-transition: all .4s ease-in-out;
    -o-transition: all .4s ease-in-out;
    transition: all .4s ease-in-out;
}

.logo:hover {
    z-index: 2;
    opacity: 1;
    background: url(http://pixellab-design.com/img/2.jpg) no-repeat;
}
于 2013-08-27T05:23:57.720 回答
0

至少对于 Firefox,根据文档background-image它是不可动画的。

相反,请尝试将两个图像放在一起并为opacity属性设置动画:

.logo {
    float: left;
    z-index: 1;
    width: 300px;
    height: 225px;
    background: url(http://pixellab-design.com/img/2.jpg) no-repeat;
    position: absolute;
}

.logotop {
    float: left;
    z-index: 2;
    width: 300px;
    height: 225px;
    background: url(http://pixellab-design.com/img/1.jpg) no-repeat;
    position: absolute;
    -moz-transition: all .4s ease;
    -webkit-transition: all .4s ease;
    -ms-transition: all .4s ease;
    -o-transition: all .4s ease;
    transition: all .4s ease;
}

.logotop:hover {
    opacity: 0;
}

HTML:

<div class="logo"></div><div class="logotop"></div>

小提琴:http: //jsfiddle.net/kYZ9Y/2/

于 2013-08-27T01:33:47.030 回答
0

可以用伪元素来完成。

.logo {
    background: url(http://via.placeholder.com/300?text=Normal) no-repeat;
    width: 300px;
    height: 300px;
    position: relative;
}
.logo:after {
    content: "";
    opacity: 0;
    display:block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: url(http://via.placeholder.com/300?text=Hover) no-repeat;
    -moz-transition: all .4s ease;
    -webkit-transition: all .4s ease;
    -ms-transition: all .4s ease;
    -o-transition: all .4s ease;
    transition: all .4s ease; 
}
.logo:hover:after {
    opacity: 1;
}

https://jsfiddle.net/84bvybjs/

于 2013-08-27T01:40:22.177 回答