温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用CSS实现小球抛物线运动动画效果的代码

发布时间:2020-04-25 16:55:06 来源:亿速云 阅读:671 作者:栢白 栏目:web开发

本篇文章给大家带来的内容是使用CSS实现小球抛物线运动动画效果的代码 ,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

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

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

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

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

    *{margin: 0;padding: 0}  /*简单的浏览器兼容*/
    /*设置初始样式*/
    .item, .item2 {
        width:20px;
        height: 20px;
        display: inline-block;
        position: absolute;
        top: 50px;
        left: 20px;
        background-color: #00aa00;
        border-radius: 50%;
    }
    /*竖直运动*/
    .wraper {
        animation: vertical-animation 2s  .5s 2;
        animation-timing-function: cubic-bezier(.11,-.33,.55,.11);
    }
    /*水平运动*/
    .wraper .item {
        animation: hor-animation 2s linear .5s 2;
    }
    @-moz-keyframes hor-animation {
        0% { transform: translateX(0px); }
        100% { transform: translateX(400px); }
    }
    @-webkit-keyframes hor-animation {
        0% { transform: translateX(0px);     }
        100% { transform: translateX(400px); }
    }
    @-moz-keyframes vertical-animation {
        0% { transform: translateY(0px);  }
        100% { transform: translateY(400px); }
    }
    @-webkit-keyframes vertical-animation {
        0% { transform: translateY(0px);     }
        100% { transform: translateY(400px); }
    }

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

以上就是使用CSS实现小球抛物线运动动画效果的代码的详细内容,更多请关注亿速云其它相关文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI