gpt4 book ai didi

css - 如何停止关键帧动画

转载 作者:行者123 更新时间:2023-11-28 11:10:40 24 4
gpt4 key购买 nike

你能告诉我如何停止关键帧动画吗?在下面的示例中,div 元素循环回到顶部并再次向下移动。能否在 div 达到 {} 条件后停止功能?

<style> 
div
{
width:100px;
height:100px;
background:red;
position:relative;
animation:mymove 5s infinite;
-webkit-animation:mymove 5s infinite; /* Safari and Chrome */
}

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

@-webkit-keyframes mymove /* Safari and Chrome */
{
from {top:0px;}
to {top:200px;}
}
</style>

<div></div>

最佳答案

你可以使用 animation-fill-modeforwards 为值的属性。

来自MDN :

forwards
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.

给你:

div {
-webkit-animation: mymove 5s forwards; /* Safari and Chrome */
/* Add other vendor-prefixes if needed */
animation: mymove 5s forwards;
}

WORKING DEMO .

关于css - 如何停止关键帧动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22000476/

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