2014-09-25 83 views
0

我正在尝试动画两张图片,以便它们以固定的时间间隔更改,但问题在于第二个图像很快就会出现并消失我需要一种方法来使延迟属性重复已审阅本,但似乎并没有工作CSS animation delay in repeating
http://jsfiddle.net/fc3nb5rL/2/以固定时间间隔更改内容的动画延迟属性

我想我的问题是在这里某处

@-webkit-keyframes anim { 
from { 
    z-index:1; 
} 
to { 
    z-index:-2; 
} 
} 
.back { 
-webkit-animation:anim 5s; 
-webkit-animation-iteration-count:infinite; 
-webkit-animation-timing-function: ease-in-out; 
} 

@-webkit-keyframes anim2 { 
from { 
    z-index:1; 
} 
to { 
    z-index:-2; 
} 
} 

回答

1

首先解决您的HTML (markup),那么你可以动画opacity而不是z-index

.container { 
 
    position:relative; 
 
    height:500px; 
 
    width:500px; 
 
    margin:0 auto; 
 
} 
 
.container img { 
 
    position:absolute; 
 
    width:100%; 
 
} 
 

 
@-webkit-keyframes anim1 { 
 
    from { 
 
     opacity:0; 
 
    } 
 
    to { 
 
     opacity:1; 
 
    } 
 
} 
 

 

 
@-webkit-keyframes anim2 { 
 
    from { 
 
     opacity:1; 
 
    } 
 
    to { 
 
     opacity:0; 
 
    } 
 
} 
 

 
[href=first] img { 
 
    opacity:0; 
 
    /*animation----:----name--duration--delay--timing function---direction----iteration count*/ 
 
    -webkit-animation: anim1 2s 0s linear alternate infinite; 
 
} 
 
[href=second] img { 
 
    opacity:1; 
 
    -webkit-animation: anim2 2s 0s linear alternate infinite; 
 
}
<div class="container"> 
 
    <a href="second"> 
 
     <img src="http://placekitten.com/300/300" /> 
 
    </a> 
 
    <a href="first"> 
 
     <img class="front" src="http://placekitten.com/300/301" /> 
 
    </a> 
 
</div>

+0

这是伟大的,但在我的代码的图片有不同的联系,但这里只有一个 – Akshay 2014-09-25 12:56:44

+0

什么是你一个链接?你的意思是源'src'? – 2014-09-25 12:59:14

+0

图像是指向特定页面的链接,每个图像都有自己的链接,但如果使用不透明度,则只有一个链接(对于放置在顶部的图像),另一个链接将具有相同的链接 – Akshay 2014-09-25 13:02:08

1
Give this a shot. I have also set it up to be cross-browser compatible. http://jsfiddle.net/fc3nb5rL/2/ 

A few things to note about CSS3 transitions. It does not know how to interpolate between the z-index  
property, as well as the display property. 
+0

抱歉把所有的代码窗口,stackoverflow告诉我我的小提琴链接需要缩进,所以我这样做,但不会让我发布,除非我缩进everythin – 2014-09-25 13:39:53

+0

感谢您帮助我,我有我的答案,使用百分比似乎在做这项工作 – Akshay 2014-09-25 13:44:14