当前位置:   article > 正文

使用CSS实现抛物线运动效果_css 抛物线

css 抛物线
    一个物体实现抛物线运动,物理上是将物体分为水平运动(匀速)和竖直运动(加速);用css3实现原理也如此,用该元素需要两层,一层控制水平,一层控制竖直;在css3中可以通过过渡或者动画-timing-function的贝塞尔曲线设置速度,贝塞尔曲线的斜率就是物体运动的速度因此对竖直方向运动设置不同的贝塞尔公式便可以得到上抛、平抛、扭曲等各样曲线运动

        本文也是看了张鑫旭老师的这回试试使用CSS实现抛物线运动效果 又进行模拟练习,写下的一篇知识积累实现效果:点击链接

       主要实现如下html部分 主要两层div 一个控制水平运动, 一个控制竖直运动

  1. <div class="wraper"> <!--控制竖直运动-->
  2. <div class="item"></div> <!--控制水平运动-->
  3. </div>
  4. <div class="item2"></div>

在css中也是比较简单 直接设置水平和竖直的运动动画 和进行动画的设置

  1. *{margin: 0;padding: 0} /*简单的浏览器兼容*/
  2. /*设置初始样式*/
  3. .item, .item2 {
  4. width:20px;
  5. height: 20px;
  6. display: inline-block;
  7. position: absolute;
  8. top: 50px;
  9. left: 20px;
  10. background-color: #00aa00;
  11. border-radius: 50%;
  12. }
  13. /*竖直运动*/
  14. .wraper {
  15. animation: vertical-animation 2s .5s 2;
  16. animation-timing-function: cubic-bezier(.11,-.33,.55,.11);
  17. }
  18. /*水平运动*/
  19. .wraper .item {
  20. animation: hor-animation 2s linear .5s 2;
  21. }
  22. @-moz-keyframes hor-animation {
  23. 0% { transform: translateX(0px); }
  24. 100% { transform: translateX(400px); }
  25. }
  26. @-webkit-keyframes hor-animation {
  27. 0% { transform: translateX(0px); }
  28. 100% { transform: translateX(400px); }
  29. }
  30. @-moz-keyframes vertical-animation {
  31. 0% { transform: translateY(0px); }
  32. 100% { transform: translateY(400px); }
  33. }
  34. @-webkit-keyframes vertical-animation {
  35. 0% { transform: translateY(0px); }
  36. 100% { transform: translateY(400px); }
  37. }

里面主要用的的就是贝塞尔曲线 斜率就是物体的运动速度 可以根据不同斜率 绘制各样的曲线运动 

 

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号