gpt4 book ai didi

html - 如何防止CSS动画回到原来的位置?

转载 作者:太空狗 更新时间:2023-10-29 13:57:22 25 4
gpt4 key购买 nike

因此,我的 CSS 在 3 秒后将一个 div 移动到 -40px。这样做之后,div 将移回其原始位置。这是代码:

#jsAlert {
width: 100%;
height: 40px;
position: absolute;
left: 0px;
top: 0px;
background-color: rgba(0, 0, 0, 0.6);
animation:mymove 3s;
animation-delay: 3s;

/*Safari and Chrome*/
-webkit-animation: mymove 2s;
-webkit-animation-delay: 2s;
}

@keyframes mymove {
from {top: 0px;}
to {top: -40px;}
}

@-webkit-keyframes mymove /*Safari and Chrome*/
{
from {top: 0px;}
to {top: -40px;}
}

如何防止 div 返回其原始位置?

最佳答案

您需要使用 animation-fill-mode值设置为 forwards

来自 Mozilla 开发者网络:

The target will retain the computed values set by the last keyframe encountered during execution. The last keyframe encountered depends on the value of animation-direction and animation-iteration-count

Demo

关于html - 如何防止CSS动画回到原来的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22594687/

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