gpt4 book ai didi

css - 将关键帧动画合二为一

转载 作者:太空宇宙 更新时间:2023-11-04 08:04:17 26 4
gpt4 key购买 nike

我有一个图像,我想“走过”一个 div,然后在最后水平翻转并以另一种方式返回。我在这里创建了一个代码笔:https://codepen.io/jessiemele/pen/rGQWWE . tinyWalk 动画在结束时变得非常有 flex ,就在它转身并回到起点之前,我假设它是从图像到达 div 的顶部。我想知道是否有一种方法可以将这两个动画结合起来,只在图像上运行它们,这样我就不必在 div 上运行 tinyWalk。我的代码在这里:

<div class="catapillarBox">
<img src="https://i.imgur.com/0XPhWfE.jpg" class="caterpillar"
alt="caterpillar drawing" />
</div>
</div>
<div class="blueBox">
<h5>I'm your box</h5>
</div>

CSS:

.blueBox {
background-color: #1d88eb;
width: 875px;
height: 400px;
margin-top: 125px;
padding-bottom: 70px;
margin-top: 150px;
z-index: 2;
}
img.caterpillar {
position: absolute;
top: 125px;
left:0;
-webkit-animation: walk 20s forwards infinite linear;
animation: walk 20s forwards infinite linear;
z-index: 3;
}
@keyframes walk{
0% { left: 0; transform: rotateY(0deg);}
49% {transform: rotateY(0deg);}
50% {left: 700px; transform: rotateY(180deg);}
99% {transform: rotateY(180deg);}
100% {left: 0; transform: rotateY(0deg);
}
.catapillarBox {
width: 200px;
height: 100px;
-webkit-animation: tinywalk 500ms linear alternate infinite;
animation: tinywalk 500ms linear alternate infinite;
}
@keyframes tinywalk {
0%{ transform: rotate(0);}
25%{ transform: rotate(-1deg);}
50%{ transform: rotate(1deg);}
75%{ transform: rotate(-1deg);}
100%{ transform: rotate(0);}
}

最佳答案

Jessica,我创建了一个代码笔 here那应该可以解决您的问题。看起来你的图像旋转对你的喜好来说太剧烈了。我将其编辑为 0.2 度旋转。尝试以下 CSS:

.blueBox {
background-color: #1d88eb;
width: 875px;
height: 400px;
margin-top: 125px;
padding-bottom: 70px;
margin-top: 150px;
z-index: 2;
}
.catapillarBox {
width: 200px;
height: 100px;
-webkit-animation: tinywalk 500ms linear alternate infinite;
animation: tinywalk 500ms linear alternate infinite;
}
@keyframes tinywalk {
0%{ transform: rotate(0);}
25%{ transform: rotate(-0.2deg);}
50%{ transform: rotate(0.2deg);}
75%{ transform: rotate(-0.2deg);}
100%{ transform: rotate(0);}
}
img.caterpillar {
position: absolute;
top: 125px;
left:0;
-webkit-animation: walk 20s forwards infinite linear;
animation: walk 20s forwards infinite linear;
z-index: 3;
}
@keyframes walk{
0% { left: 0; transform: rotateY(0deg);}
49% {transform: rotateY(0deg);}
50% {left: 700px; transform: rotateY(180deg);}
99% {transform: rotateY(180deg);}
100% {left: 0; transform: rotateY(0deg);
}

关于css - 将关键帧动画合二为一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46778157/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com