幻灯片动画的麻烦

时间:2013-02-21 18:30:32

标签: html css

我是一名没有太多CSS经验的开发人员。我想用两个图像创建一个纯CSS3幻灯片。我发现some nifty code这样做了,我在下面实现了一个非常小的变化(基本上我只是为#cf3取出了img .top id选择器:

.slide {
    position:absolute;
}   

@keyframes cf3FadeInOut {
    0% {
          opacity:1;

}           
45% {
    opacity:1;

}           
55% {       
    opacity:0;

}       
100% {  
    opacity:0;

}       

}

img.top {
    animation-name: cf3FadeInOut;
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
    animation-duration: 10s;
    animation-direction: alternate;

}

第一张图片定义为<img class="slideshow top" src="img1.jpg">。第二个是相同的,除了没有"top"类。

当我加载页面时,我的所有其他CSS都可以使用,但动画无处可寻。谁知道我哪里出错了?

1 个答案:

答案 0 :(得分:0)

您需要添加供应商特定的属性名称,CSS3 animation仍然是草案规范。

-webkit-animation-name: cf3FadeInOut;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: 10s;
-webkit-animation-direction: alternate;

-moz-animation-name: cf3FadeInOut;
-moz-animation-timing-function: ease-in-out;
-moz-animation-iteration-count: infinite;
-moz-animation-duration: 10s;
-moz-animation-direction: alternate;

-o-animation-name: cf3FadeInOut;
-o-animation-timing-function: ease-in-out;
-o-animation-iteration-count: infinite;
-o-animation-duration: 10s;
-o-animation-direction: alternate;

animation-name: cf3FadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 10s;
animation-direction: alternate;

/* and all the keyframes too */
@-webkit-keyframes cf3FadeInOut { ... }
@-moz-keyframes cf3FadeInOut { ... }
@-o-keyframes cf3FadeInOut { ... }
@keyframes cf3FadeInOut { ... }