Jes*_*eTG 2 css animation keyframe css-animations
我有一个CSS关键帧动画,它本身非常普通。但是,我希望能够强制动画处于特定帧。 类似的东西anim.setProgress(0.13),它将动画设置为13%。 我怎样才能做到这一点?
请注意,我不只是想在任意点开始动画。我希望能够中断它并说“回到32%”之类的值,而不管动画沿多远。
给动画一个负值animation-delay。对于运行10秒的动画,将以定位13%的帧-1.3s。
如果“ animation-delay”的值是负的时间偏移,则动画将在应用动画的那一刻执行,但似乎已在指定的偏移处开始执行。也就是说,动画似乎在其播放周期的中途开始。在动画具有隐含的起始值和负的“动画延迟”的情况下,起始值是从应用动画的那一刻起获取的。
div.loading {
animation: loading 10s linear 1;
animation-play-state: paused;
animation-delay: -1.3s;
/*start at 13%*/
}
div.ten-seconds {
animation-delay: -1s;
/*start at 10%*/
}
div.zero-seconds {
animation-delay: 0s;
/*start at 0%*/
}
/*Note how the keyframes start at 0 width*/
@keyframes loading {
0% {
width: 0;
}
100% {
width: 100%;
}
}
/*Just for this example below*/
input {
display: none
}
label {
display: block;
background: gray;
width: 120px;
height: 50px;
line-height: 50px;
text-align: center;
font-size: 20px;
margin: 20px 0 20px 0;
color: #FFF;
cursor: pointer;
}
input:checked ~ .loading {
animation-play-state: running;
}
div {
height: 100px;
background: pink;
}
div.ruler {
width: 13%;
height: 20px;
line-height: 20px;
text-align: center;
color: #FFF;
background: gray;
border-bottom: solid 2px #000;
}
div.ruler.bottom {
width: 10%;
}Run Code Online (Sandbox Code Playgroud)
<input type="checkbox" id="start" />
<label for="start">Start / Pause</label>
<div class="ruler">Go 13%</div>
<div class="loading"></div>
<div class="ruler bottom">Go 10%</div>
<div class="loading ten-seconds"></div>
<h2>No delay below</h2>
<div class="loading zero-seconds"></div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
965 次 |
| 最近记录: |