css动画如何让球反弹

标签 css animation

我目前正在学习 CSS 动画,我想知道如何平滑地将球弹起然后再次落下,目前它平滑上升但一旦到达顶部并再次开始就会重置(与下降相反再次下降)

.football {
 background-image:url('football.png');
 height:45px;
 width:45px;
 top:100%;
 left:40%;
 position:absolute;
 animation:football_up_down 1s linear infinite;
}

@keyframes football_up_down {  
 100% { transform:rotate(360deg); top:30%;  } 
 0% { transform:rotate(180deg); top:100%} 

}

最佳答案

正如他们在评论中所说,您可以添加 animation-direction: alternate

但您也可以添加一个 50% 点作为峰值点,然后添加一个 100% 点复制 0%。将先前关键帧的旋转 Angular 相加可以为重复添加更逼真的效果。即:

@keyframes football_up_down {  
  0% { transform:rotate(180deg); top:100% } 
  50% { transform:rotate(360deg); top:30%; } 
  100% { transform:rotate(540deg); top:100% } 
}

工作示例:http://jsfiddle.net/w2mH8/

关于css动画如何让球反弹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24450543/

相关文章:

html - WP样式问题

javascript - android 2.x - 4.3.x phonegap 不支持 flexbox css3

android.graphics.BitmapFactory.nativeDecodeAsset( native 方法)中的 java.lang.OutOfMemoryError

html - 我想对我的布局网格许愿

angular - 在 flex 元素之间显示一个 div

html - 如何停止下拉菜单成为导航栏的一部分?

ios - 如何使用 UIView.animate 创建 U 形动画? - swift

swift - 如何在 RealityKit 中为变换设置动画

jquery - 为什么我的 jquery 回调提前触发?

javascript - 在 Angular 2 中应用频繁 CSS 更改的最有效方法