gpt4 book ai didi

html - 向一个元素添加 2 个 css 动画

转载 作者:行者123 更新时间:2023-11-28 02:28:38 26 4
gpt4 key购买 nike

我有 2 个元素,一个是矩形,另一个是直线。完成后,我将 rect 从左向右移动,然后旋转 line。然后我想要的是,一旦线旋转,我想改变 rect 的背景颜色。

.rect {
position: absolute;
left: 0;
width: 100px;
height: 100px;
background: red;
animation: move 1s;
animation-fill-mode: forwards;
}

.line {
position: absolute;
top: 200px;
left: 100px;
height: 100px;
border-right: 2px solid green;
animation: rotate 1s;
animation-fill-mode: forwards;
animation-delay: 1.3s;
}

@-webkit-keyframes move {
to {
left: 200px;
}
}

@-webkit-keyframes rotate {
to {
transform: rotate(360deg);
}
}
<div class="rect"></div>
<div class="line"></div>

JSFiddle

最佳答案

你可以用逗号分隔多个动画。只需将动画延迟添加到第二个改变颜色的动画

.rect {
position: absolute;
left: 0;
width: 100px;
height: 100px;
background: red;
animation: move 1s, colorChange 1s 2s;
animation-fill-mode: forwards;
}

.line {
position: absolute;
top: 200px;
left: 100px;
height: 100px;
border-right: 2px solid green;
animation: rotate 1s;
animation-fill-mode: forwards;
animation-delay: 1.3s;
}

@-webkit-keyframes move {
from {}
to {
left: 200px;
}
}

@-webkit-keyframes rotate {
from {}
to {
transform: rotate(360deg);
}
}

@keyframes colorChange {
to {
background-color: green;
}
}
<div class="rect"></div>
<div class="line"></div>

关于html - 向一个元素添加 2 个 css 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52346267/

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