How to move to the certain keyframe in CSS3 animation?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 01:53:05

问题


Let's say we have an animation like here: http://jsfiddle.net/utterstep/JPDwC/

Layout:

<div>back</div>
<div class="animating"></div>
<div>forward</div>

And corresponding CSS:

@keyframes someanimation {
    0% {
        width: 100px;
    }
    50% {
        width: 200px;
    }
    100% {
        width: 100px;
    }
}

.animating {
    width: 200px;
    height: 200px;
    background-color: red;
    animation: someanimation 5s infinite;
}

And I want to go to the next or previous animation state when I press back or forward. There can be more than one object and I would like to switch their animation states at the same time.

Is it someway possible via CSS or CSS+JS, or it maybe it will be easier for me just to rewrite my code in pure-JS? (currently I don't like this idea because I have a lot of properties to animate and CSS makes it much more easier for me)


回答1:


Perhaps you have got the answer in CSS+JS

Please refer Old Post

Here on fiddle from the same post Fiddle

And with CSS only here is the Fiddle I have tweaked with :hover property,

it changes the animation on hover, just like back button

I hope this will solve your purpose..



来源:https://stackoverflow.com/questions/17644884/how-to-move-to-the-certain-keyframe-in-css3-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!