DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> HTML基礎知識 >> HTML5詳解
CSS3 小動畫:用 @keyframes 做一顆會彈跳的小球
編輯:HTML5詳解     

這個小 demo 的關鍵在於用 @keyframes 把 top 的位移與 scaleX、scaleY 的形變綁在一起:落下時壓扁、彈起時拉長,再搭配 ease-in / ease-out 的節奏切換,反彈的手感就會真實很多。

HTML

<div class="ball"></div>

CSS

body { background: #fff; }

.ball {
   position: absolute;
   top: 0;
   left: 50%;
   z-index: 11;
   margin: 0 0 0 -8px;
   width: 200px;
   height: 130px;
   border-radius: 50%;
   background: url(/School/UploadFiles_7810/201603/20160313141641745.gif?1) #57abdb;
   animation: jump 4s infinite forwards;
}

@keyframes jump {
   0%, 100% {
     top: 0%;
     transform: scaleX(1.1) scaleY(0.9);
     animation-timing-function: ease-in;
   }
   40% {
     top: 80%;
     transform: scaleX(1) scaleY(1);
   }
   55% {
     top: 90%;
     transform: scaleX(1.8) scaleY(0.2);
     animation-timing-function: ease-in-out;
   }
   65% {
     top: 30%;
     transform: scaleX(.6) scaleY(1.4);
     animation-timing-function: ease-out;
   }
   80% {
     transform: scaleX(1) scaleY(1);
   }
}

幾個可以玩的細節:55% 那格把 Y 軸壓到 0.2、X 軸拉到 1.8,是觸地瞬間的挤压感;65% 反向拉長模擬離地加速;每個 keyframe 各自指定 timing-function,讓每一段的加速曲線都不同,整體節奏會比全域統一設定自然得多。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved