【发布时间】:2018-04-21 23:26:26
【问题描述】:
我在 CSS Animation 上遇到动画延迟问题。我有 3 张图片,我想制作幻灯片。插图是,图像 1 到图像 2 需要 15 秒才能改变,图像 2 到图像 3 需要 15 秒才能改变,图像 3 回到图像 1 需要 30 秒,在第一个循环之后,我想让幻灯片结束图像 3 所以图像 1 到图像 2 仍为 15 秒,图像 2 到图像 3 仍为 15 秒,当图像 3 加载时无需返回图像 1。我尝试了此代码,但它给了我 15 秒的所有图像延迟。这是我的代码:
ul {
list-style: none;
margin: 0;
padding: 0;
position: relative;
}
li {
position: absolute;
opacity:0;
}
li {
animation: xfade 45s infinite;
}
li:nth-child(2) {
animation-delay:15s;
}
li:nth-child(3) {
animation-delay:30s;
}
@keyframes xfade{
3%{opacity:1}
33% {opacity:1;}
36%{opacity:0}
}
<ul>
<li><img width="500" height="500" src="http://lorempixel.com/500/500/sports" alt="pic1"></li>
<li><img width="500" height="500" src="http://lorempixel.com/500/500/people" alt="pic2"></li>
<li><img width="500" height="500" src="http://lorempixel.com/500/500/transport" alt="pic3"></li>
</ul>
我想根据上面的插图延迟我的动画。任何人都可以帮我解决这个问题吗?之前谢谢你。
【问题讨论】:
-
这是最好的解决方案,但为此,您必须使用 gsap 动画,因为 CSS 动画不是我们想要的。因此,为了获得最佳效果,您必须使用 gsap 动画,这很容易。这是直播网址greensock.com/gsap
-
@HardenRahul 感谢您的建议。但是,GSAP 使用了 javascript,我不能使用 javascript,因为我的客户不想使用 javascript。
-
那么你可以使用代码笔中的这个例子这里是 URL:codepen.io/daysahead/pen/mJqBge
-
@Antonio 也检查我的解决方案。