简体   繁体   English

关键帧动画:先滑动然后旋转

[英]keyframes animation: slide then rotate

I am trying to slide in some text and create a 'bounce effect' as if it is hitting a wall, before settling in a position. 我试图滑动一些文本并创建一个“反弹效果”,就像它碰到墙一样,然后再安置到某个位置。

However, whenever I add rotation, it rotates WHILST moving, not once it has reached a certain point. 但是,无论何时添加旋转,它都会旋转WHILST移动,而不是一旦到达某个点。

In summary - I want the div to rotate ONCE it hits -30px, then go back to no rotate, then move the other way, before settling in place. 总结-我希望div旋转一次,使其达到-30px,然后返回不旋转,然后以其他方式移动,然后再就位。

Here is my current CSS... 这是我目前的CSS ...

@-webkit-keyframes slide {
from {right: 1500px ; -webkit-transform: rotate(0deg)} 
50% {right: -30px, ; -webkit-transform:rotate(5deg)} 
75% { right: 20px} 
to {right: 0px}
}

div {
-webkit-animation: slide 5s;
}

going from one point to another, the animation is implemented gradually. 从一个点到另一个,动画是逐步实现的。 If you want it to start at 50%, you need to explicitly specify 0 degrees at 50%, and 5 degrees later, then again 0 degrees at a later point. 如果要从50%开始,则需要在50%处显式指定0度,然后在5度后显式指定,然后在以后的位置再次指定0度。 THis should be what you are looking for: 这应该是您想要的:

@-webkit-keyframes slide {
0% {right: 1500px;} 
50% {right: -30px; -webkit-transform:rotate(0deg)} 
55% {right: -30px; -webkit-transform:rotate(5deg)}
65% {right: -30px; -webkit-transform:rotate(0deg)}
75% { right: 20px} 
100% {right: 0px}
}

div {
-webkit-animation: slide 5s;
}

Note that i specified "right: -30px;" 请注意,我指定了“ right:-30px;” three times. 三次。 Otherwise the animation would move on to your next specified value and start implementing that animation, which is positive 20px. 否则,动画将移至下一个指定值,并开始实施该动画,该动画为正20px。

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

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