CSS實現小球拋物線運動的動畫效果 (代碼)

來源:互聯網
上載者:User
本篇文章給大家帶來的內容是關於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); }    }

裡面主要用的的就是貝茲路徑 斜率就是物體的運動速度 可以根據不同斜率 繪製各樣的曲線運動

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.