標籤:des style blog http color io os 使用 ar
原文:CSS 實現載入動畫之三-鋼琴按鍵
今天做的這個動畫實現也是非常簡單,簡單數幾行代碼就可以搞定。給這個動畫取了個優雅的名字--鋼琴按鍵,也實在是想不出什麼更形象的名字了。廢話不多說,直接。
1. 先看gif圖
2. 代碼實現思路
2.1 定義五個方塊的元素。
2.2 對方塊元素使用動畫,延時改變透明度。
3. 主要使用的技術
主要用到了animation動畫
@-webkit-keyframes load{
0%{opacity:1;}
100%{opacity:0;}
}
.m-load2 .item{-webkit-animation:load 0.5s linear 0s infinite;}
4. 原始碼
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" Content="text/html; charset=utf-8;"> 5 <title>CSS3實現載入的動畫效果3</title> 6 <meta name="author" content="rainna" /> 7 <meta name="keywords" content="rainna‘s css lib" /> 8 <meta name="description" content="CSS3" /> 9 <style>10 *{margin:0;padding:0;}11 .m-load{background:url(‘load.gif‘) center center no-repeat;}12 13 .m-load,.m-load2{width:60px;height:10px;margin:100px auto;}14 15 /** 載入動畫的靜態樣式 **/16 .m-load2:before,.m-load2:after,.m-load2 .item{float:left;width:10px;height:10px;margin:0 2px 0 0;background:#444;}17 .m-load2:before,.m-load2:after{content:‘‘;}18 19 /** 載入動畫 **/20 @-webkit-keyframes load{21 0%{opacity:1;}22 100%{opacity:0;}23 }24 .m-load2:before{-webkit-animation:load 0.5s linear 0s infinite;}25 .m-load2 .item:nth-child(1){-webkit-animation:load 0.5s linear 0.1s infinite;}26 .m-load2 .item:nth-child(2){-webkit-animation:load 0.5s linear 0.2s infinite;}27 .m-load2 .item:nth-child(3){-webkit-animation:load 0.5s linear 0.3s infinite;}28 .m-load2:after{-webkit-animation:load 0.5s linear 0.4s infinite;}29 </style>30 </head>31 32 <body>33 <div class="m-load"></div>34 35 <div class="m-load2">36 <div class="item"></div>37 <div class="item"></div>38 <div class="item"></div>39 </div>40 </body>41 </html>
CSS 實現載入動畫之三-鋼琴按鍵