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

本文基于张鑫旭老师的内容进行模拟练习,介绍使用CSS实现抛物线运动效果。主要通过两层div分别控制水平和竖直运动,在CSS中设置水平和竖直的运动动画。核心是利用贝塞尔曲线,根据不同斜率绘制曲线运动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

       主要实现如下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); }
    }

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值