我有触发轨道动画的 .orbit 类。我删除了该类以停止轮换。这会将元素重置为其原始位置。
有没有办法停止旋转动画,将元素留在原来的位置?
目前正在获取位置并将其设置为该位置,但并不完美。
https://jsfiddle.net/f4hnz2va/2/
#errordot{
position:absolute;
top:0;
left:0;
width:50px;
height:50px;
background:red;
border-radius:50%;
font-size:40px;
}
#errorsun{
width:200px;
height:200px;
position:absolute;
top:50px;
left:50px;
}
.orbit {
-webkit-animation-iteration-count:infinite;
-webkit-animation-timing-function:linear;
-webkit-animation-name:orbit;
-webkit-animation-duration:5s;
}
@-webkit-keyframes orbit {
from { -webkit-transform:rotate(0deg) }
to { -webkit-transform:rotate(360deg) }
}
@-moz-keyframes orbit {
from { -moz-transform:rotate(0deg) }
to { -moz-transform:rotate(360deg) }
}
Run Code Online (Sandbox Code Playgroud)
您需要的不是“停止”轨道动画,而是使用 CSS3animation-play-state属性“暂停”它。如果您想永远暂停它并且不再恢复,可以应用标记变量(例如“hasPaused”)。
示例 jsfiddle 可以在以下位置找到: https ://jsfiddle.net/cshao/1kb8cm7j/1/