CSS 实现加载动画之五-光盘旋转
今天做的這個(gè)動(dòng)畫(huà)叫光盤(pán)旋轉(zhuǎn),名字自己取的。動(dòng)畫(huà)的效果估計(jì)很多人都很熟悉,就是微信朋友圈里的加載動(dòng)畫(huà)。做過(guò)前面幾個(gè)動(dòng)畫(huà),發(fā)現(xiàn)其實(shí)都一個(gè)原理,就是如何將動(dòng)畫(huà)的元素如何分離出來(lái)。這個(gè)動(dòng)畫(huà)的實(shí)現(xiàn)也很簡(jiǎn)單,關(guān)鍵點(diǎn)在于如何將元素拼湊成風(fēng)車(chē)形狀。然后定義動(dòng)畫(huà)的關(guān)鍵幀為rotate 360度,應(yīng)用于整個(gè)元素上,就可以使整個(gè)元素旋轉(zhuǎn)起來(lái)。案例在請(qǐng)?jiān)赾hrome中查看。
?
1. 先看截圖
?
2. 代碼實(shí)現(xiàn)思路
2.1 首先還是定義四個(gè)元素,元素的中心為這四個(gè)元素組成的圓的圓心。這樣定義的目的可以保證元素拼湊成一個(gè)正圓。
2.2 在單個(gè)元素的頭尾各定義一個(gè)子元素,子元素旋轉(zhuǎn)一定的角度,使其平行排列,中間剛好留一個(gè)正圓的位置。這里用了rotate和translate屬性,沒(méi)有用skew屬性,是因?yàn)閟kew方法會(huì)使元素拉伸后變小。
2.3 將每個(gè)元素的子元素都定義不同的背景色,定義完成后,會(huì)形成8個(gè)不同的顏色排列,此時(shí)元素的形狀已經(jīng)產(chǎn)生了。需要注意的是,最后一個(gè)元素需要裁剪下,因?yàn)橛锌赡軙?huì)覆蓋第一個(gè)元素。案例中第4,8個(gè)子元素是分開(kāi)寫(xiě)的。
2.4 此時(shí)在圓心位置定義一個(gè)圓,圓的大小剛好覆蓋中間的空隙位置。外層容器也設(shè)為一個(gè)圓,大小為能全部顯示所有的背景顏色,多余的部分截?cái)嚯[藏。
2.5 定義動(dòng)畫(huà),并在外層容器上應(yīng)用這個(gè)動(dòng)畫(huà)。這個(gè)動(dòng)畫(huà)的方式比較簡(jiǎn)單,就是旋轉(zhuǎn),直接使用rotate即可。
?
3. 源代碼
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" Content="text/html; charset=utf-8;"> 5 <title>CSS3實(shí)現(xiàn)加載的動(dòng)畫(huà)效果5</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 body{background:#464646;} 12 13 .m-load{width:490px;height:330px;margin:100px auto;background:url('load.png') center center no-repeat;} 14 15 /** 加載動(dòng)畫(huà)的靜態(tài)樣式 **/ 16 .m-load2{position:relative;width:52px;height:52px;margin:0 auto;border-radius:52px;border:2px solid #fff;overflow:hidden;} 17 .m-load2 .item{position:absolute;left:50%;top:0;width:20px;height:100%;margin-left:-10px;} 18 .m-load2 .item:nth-child(2){-webkit-transform:rotate(45deg);} 19 .m-load2 .item:nth-child(3){-webkit-transform:rotate(90deg);} 20 .m-load2 .item:nth-child(4){-webkit-transform:rotate(135deg);clip:rect(-26px,18px,26px,-18px);} 21 .m-load2 .item:nth-child(5){-webkit-transform:rotate(135deg);clip:rect(26px,37px,78px,2px);} 22 .m-load2 .item:before,.m-load2 .item:after{content:'';position:absolute;left:0;width:18px;height:100%;} 23 .m-load2 .item:before{bottom:52%;border-left:2px solid #fff;-webkit-transform-origin:left bottom;-webkit-transform:translate(100%,0) rotate(-45deg);} 24 .m-load2 .item:after{top:52%;border-right:2px solid #fff;-webkit-transform-origin:right top;-webkit-transform:translate(-100%,0) rotate(-45deg);} 25 .m-load2 .item:nth-child(1):before{background:#48ec53;} 26 .m-load2 .item:nth-child(1):after{background:#f75e5a;} 27 .m-load2 .item:nth-child(2):before{background:#a6ea4b;} 28 .m-load2 .item:nth-child(2):after{background:#724dee;} 29 .m-load2 .item:nth-child(3):before{background:#e8d84b;} 30 .m-load2 .item:nth-child(3):after{background:#44abec;} 31 .m-load2 .item:nth-child(4):before{background:#fdc103;} 32 .m-load2 .item:nth-child(5):after{background:#51ddeb;} 33 34 .m-load2 .point{position:absolute;left:50%;top:50%;width:18px;height:18px;margin:-9px 0 0 -9px;border-radius:18px;background:#464646;} 35 36 /** 加載動(dòng)畫(huà) **/ 37 @-webkit-keyframes load{ 38 100%{-webkit-transform:rotate(360deg);} 39 } 40 .m-load2{-webkit-animation:load 1.8s linear infinite;} 41 </style> 42 </head> 43 44 <body> 45 <div class="m-load"></div> 46 47 <div class="m-load2"> 48 <div class="item"></div> 49 <div class="item"></div> 50 <div class="item"></div> 51 <div class="item"></div> 52 <div class="item"></div> 53 <div class="point"></div> 54 </div> 55 </body> 56 </html>?
轉(zhuǎn)載于:https://www.cnblogs.com/zourong/p/3998485.html
總結(jié)
以上是生活随笔為你收集整理的CSS 实现加载动画之五-光盘旋转的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
                            
                        - 上一篇: 官网链接下载QT5 Creator
 - 下一篇: 四叶草Clover引导界面的快捷键大全