简体   繁体   English

CSS3动画表现异常

[英]CSS3 animation behaves unexpectedly

I have been working on an animation of a ball rolling and falling off an edge. 我一直在研究球滚动并掉落边缘的动画。 First, I made a version which just rolls, and then stops. 首先,我制作了一个可以滚动然后停止的版本。 Working fine. 工作正常。 But then, when I added the falling animation to the same code, it doesn't roll it, and I can't do anything about it. 但是,当我将下降动画添加到同一代码中时,它不会滚动,并且对此也无能为力。 Here is the first snippet: 这是第一个片段:

@-webkit-keyframes roll{
    0% {
        -webkit-animation-timing-function: ease-in; 
        -webkit-transform: translateX(0px) rotate(0deg);
    }
    100% {
        -webkit-transform: translateX(480px) rotate(360deg);
    }
}

then the second: 然后第二个:

@-webkit-keyframes rollandfall{
0% {
    -webkit-animation-timing-function: ease-in; 
    -webkit-transform: translateX(0px) rotate(0deg);
}
50% {
    -webkit-transform: translateX(480px) rotate(360deg);
}
85% {
    -webkit-animation-timing-function: ease-in;
    -webkit-transform: translate(480px, 400px) rotate(360deg);
}
95% {
    animation-timing-function: ease-out;
    -webkit-transform: translate(480px, 380px);
}
100% {
    animation-timing-function: ease-in;
    -webkit-transform: translate(480px, 400px);
}
}

(I know it's only for safari and chrome, but I want to finish it before making it accessible in every browser) And here is the link to the animation. (我知道它仅适用于Safari和chrome,但我想先完成它,然后才能在每个浏览器中访问它) 这里是动画的链接。

Thanks for any help! 谢谢你的帮助!

EDIT: It seems it wasn't exactly clear what I want it to do, so here you can check out what the first snippet does. 编辑:似乎还不太清楚我想要它做什么,因此在这里您可以查看第一个代码片段的作用。

A better way, seems to 'chain' the animations: 更好的方法似乎是“链接”动画:

#goRight img:hover{
    -webkit-animation: roll 1s, fall 1s;
    -webkit-animation-delay: 0s, 1s;
    -webkit-animation-fill-mode: forwards;
}
@-webkit-keyframes roll{
    0% {
        -webkit-animation-timing-function: ease-in; 
        -webkit-transform: translateX(0px) rotate(0deg);
    }
    100% {
        -webkit-transform: translateX(480px) rotate(360deg);
    }
}

@-webkit-keyframes fall{
    0% {
        -webkit-animation-timing-function: ease-in; 
        -webkit-transform: translateX(480px);
    }
    100% {
        -webkit-transform: translateX(480px) translateY(400px);
    }
}

Much cleaner! 干净得多!

disclaimer: I'm no expert in CSS3, but after some tweaking, this seems to work... ish. 免责声明:我不是CSS3方面的专家,但是经过一些调整后,这似乎行得通... ish。

@-webkit-keyframes rollandfall{
    0% {
        -webkit-animation-timing-function: ease-in; 
        -webkit-transform: translateX(0px) rotate(0deg);
    }
    5% {
        -webkit-animation-timing-function: ease-in;
        -webkit-transform: translateX(48px) rotate(36deg);
    }
    25% {
        -webkit-animation-timing-function: ease-in;
        -webkit-transform: translateX(240px) rotate(180deg);
    }
    30% {
        -webkit-animation-timing-function: ease-in;
        -webkit-transform: translateX(284px) rotate(216deg);
    }
    50% {
        -webkit-animation-timing-function: ease-in;
        -webkit-transform: translateX(480px) rotate(360deg);
    }
    100% {
        animation-timing-function: ease-in;
        -webkit-transform: translate(480px, 400px) rotate(360deg);
    }
}

I've created some smaller increments, to tell the engine it should animate in a certain direction; 我创建了一些较小的增量,以告诉引擎它应该朝某个方向进行动画处理。 if you put 180deg half way, it seems to roll in the opposite direction. 如果您将180deg放到一半,它似乎朝相反的方向滚动。

Needs some tweaking for a smoother animation, probably. 可能需要一些调整才能使动画更流畅。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM