來奇瘦!跟著我動(dòng)手寫一個(gè)css3加載動(dòng)畫!

很多前端開發(fā)者可能和我一樣醇坝,對(duì)于css3的動(dòng)畫寫的不多次坡,遇到產(chǎn)品強(qiáng)制加特技,趕緊上網(wǎng)搜案例宋距!呵呵噠症脂!當(dāng)然作為乘著HTML5熱潮的前端開發(fā)者淫僻,不會(huì)手寫幾個(gè)高逼格的動(dòng)畫壶唤,你怎么和老革命家劃清界限呢?對(duì)吧闸盔!來上馬迎吵!
今天我呢,帶著大家做一個(gè)加載的動(dòng)畫效果击费!
說到動(dòng)畫就要用到animation啦,來餓補(bǔ)一下:
描述
animation-name
規(guī)定需要綁定到選擇器的 keyframe 名稱。瞬铸。

animation-duration
規(guī)定完成動(dòng)畫所花費(fèi)的時(shí)間嗓节,以秒或毫秒計(jì)。

animation-timing-function
規(guī)定動(dòng)畫的速度曲線拦宣。

animation-delay
規(guī)定在動(dòng)畫開始之前的延遲。

animation-iteration-count
規(guī)定動(dòng)畫應(yīng)該播放的次數(shù)绸罗。

animation-direction
規(guī)定是否應(yīng)該輪流反向播放動(dòng)畫豆瘫。
原諒我借用一下w3cschool的資源哈,不過建議大家去菜鳥教程看文檔育灸,會(huì)比較全昵宇,當(dāng)然對(duì)著官方文檔效果會(huì)更好一些。
看一下整頁的代碼:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<style type="text/css">
.div1
{
    border-radius:50px;
    width:100px;
    height:100px;
    background:red;
    left: 0;
    top: 0;
    position:absolute;
    animation-name:myfirst1;
    animation-duration:5s;
    animation-timing-function:linear;
    animation-delay:0s;
    animation-iteration-count:infinite;
    animation-direction:alternate;
    animation-play-state:running;
    /* Safari and Chrome: */
    -webkit-animation-name:myfirst1;
    -webkit-animation-duration:5s;
    -webkit-animation-timing-function:linear;
    -webkit-animation-delay:0s;
    -webkit-animation-iteration-count:infinite;
    -webkit-animation-direction:alternate;
    -webkit-animation-play-state:running;
}
.div2{
    border-radius:50px;
    width:100px;
    height:100px;
    left:200px 
    top:0px;
    background:yellow;
    position:absolute;
    animation-name:myfirst2;
    animation-duration:5s;
    animation-timing-function:linear;
    animation-delay:0s;
    animation-iteration-count:infinite;
    animation-direction:alternate;
    animation-play-state:running;
    /* Safari and Chrome: */
    -webkit-animation-name:myfirst2;
    -webkit-animation-duration:5s;
    -webkit-animation-timing-function:linear;
    -webkit-animation-delay:0s;
    -webkit-animation-iteration-count:infinite;
    -webkit-animation-direction:alternate;
    -webkit-animation-play-state:running;
}
.div3{
    border-radius:50px;
    width:100px;
    height:100px;
    left:200px 
    top:200px;
    background:blue;
    position:absolute;
    animation-name:myfirst3;
    animation-duration:5s;
    animation-timing-function:linear;
    animation-delay:0s;
    animation-iteration-count:infinite;
    animation-direction:alternate;
    animation-play-state:running;
    /* Safari and Chrome: */
    -webkit-animation-name:myfirst3;
    -webkit-animation-duration:5s;
    -webkit-animation-timing-function:linear;
    -webkit-animation-delay:0s;
    -webkit-animation-iteration-count:infinite;
    -webkit-animation-direction:alternate;
    -webkit-animation-play-state:running;
}
.div4{
    border-radius:50px;
    width:100px;
    height:100px;
    left:0px 
    top:200px;
    background:green;
    position:absolute;
    animation-name:myfirst4;
    animation-duration:5s;
    animation-timing-function:linear;
    animation-delay:0s;
    animation-iteration-count:infinite;
    animation-direction:alternate;
    animation-play-state:running;
    /* Safari and Chrome: */
    -webkit-animation-name:myfirst4;
    -webkit-animation-duration:5s;
    -webkit-animation-timing-function:linear;
    -webkit-animation-delay:0s;
    -webkit-animation-iteration-count:infinite;
    -webkit-animation-direction:alternate;
    -webkit-animation-play-state:running;
}
@keyframes myfirst1
{
    0%   {background:red; left:300px; top:300px;}
    25%  {background:yellow; left:500px; top:300px;}
    50%  {background:blue; left:500px; top:500px;}
    75%  {background:green; left:300px; top:500px;}
    100% {background:red; left:300px; top:300px;}
}

@-webkit-keyframes myfirst1 /* Safari and Chrome */
{
    0%   {background:red; left:300px; top:300px;}
    25%  {background:yellow; left:500px; top:300px;}
    50%  {background:blue; left:500px; top:500px;}
    75%  {background:green; left:300px; top:500px;}
    100% {background:red; left:300px; top:300px;}
}
@keyframes myfirst2
{
    0%   {background:yellow; left:500px; top:300px;}
    25%  {background:blue; left:500px; top:500px;}
    50%  {background:green; left:300px; top:500px;}
    75%  {background:red; left:300px; top:300px;}
    100% {background:yellow; left:500px; top:300px;}
}

@-webkit-keyframes myfirst2 /* Safari and Chrome */
{
    0%   {background:yellow; left:500px; top:300px;}
    25%  {background:blue; left:500px; top:500px;}
    50%  {background:green; left:300px; top:500px;}
    75%  {background:red; left:300px; top:300px;}
    100% {background:yellow; left:500px; top:300px;}
}
@keyframes myfirst3
{
    0%   {background:blue; left:500px; top:500px;}
    25%  {background:green; left:300px; top:500px;}
    50%  {background:red; left:300px; top:300px;}
    75%  {background:yellow; left:500px; top:300px;}
    100% {background:blue; left:500px; top:500px;}
}

@-webkit-keyframes myfirst3 /* Safari and Chrome */
{
    0%   {background:blue; left:500px; top:500px;}
    25%  {background:green; left:300px; top:500px;}
    50%  {background:red; left:300px; top:300px;}
    75%  {background:yellow; left:500px; top:300px;}
    100% {background:blue; left:500px; top:500px;}
}
@keyframes myfirst4
{
    0%   {background:green; left:300px; top:500px;}
    25%  {background:red; left:300px; top:300px;}
    50%  {background:yellow; left:500px; top:300px;}
    75%  {background:blue; left:500px; top:500px;}
    100% {background:green; left:300px; top:500px;}
}

@-webkit-keyframes myfirst4 /* Safari and Chrome */
{
    0%   {background:green; left:300px; top:500px;}
    25%  {background:red; left:300px; top:300px;}
    50%  {background:yellow; left:500px; top:300px;}
    75%  {background:blue; left:500px; top:500px;}
    100% {background:green; left:300px; top:500px;}
}
</style>
<body style="">
<div class="Center-Container">
    <div class="div1">
    </div>
    <div class="div2">
    </div>
    <div class="div3">
    </div>
    <div class="div4">
    </div>
</div>
</body>
</html>

html的結(jié)構(gòu)很簡單哈恩够,精華都在css里了,有興趣的童鞋復(fù)制下來運(yùn)行一下蜂桶,還是有點(diǎn)逼格的哈,這次分享的是平面動(dòng)畫腰湾,下次給大家來個(gè)炫酷的3d效果疆股!加特技 不收費(fèi)!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末附井,一起剝皮案震驚了整個(gè)濱河市两残,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌人弓,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,734評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件意蛀,死亡現(xiàn)場(chǎng)離奇詭異健芭,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)魁蒜,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,931評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門吩翻,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人细移,你說我怎么就攤上這事熊锭⊙┙模” “怎么了精绎?”我有些...
    開封第一講書人閱讀 164,133評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長旬牲。 經(jīng)常有香客問我搁吓,道長,這世上最難降的妖魔是什么堕仔? 我笑而不...
    開封第一講書人閱讀 58,532評(píng)論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮通贞,結(jié)果婚禮上恼五,老公的妹妹穿的比我還像新娘。我一直安慰自己唤冈,他們只是感情好银伟,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,585評(píng)論 6 392
  • 文/花漫 我一把揭開白布彤避。 她就那樣靜靜地躺著,像睡著了一般琉预。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上卒暂,一...
    開封第一講書人閱讀 51,462評(píng)論 1 302
  • 那天娄帖,我揣著相機(jī)與錄音,去河邊找鬼近速。 笑死堪旧,一個(gè)胖子當(dāng)著我的面吹牛奖亚,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播爆袍,決...
    沈念sama閱讀 40,262評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼李滴,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了谆扎?” 一聲冷哼從身側(cè)響起芹助,我...
    開封第一講書人閱讀 39,153評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎无蜂,沒想到半個(gè)月后蒙谓,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,587評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡酣倾,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,792評(píng)論 3 336
  • 正文 我和宋清朗相戀三年谤专,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片映之。...
    茶點(diǎn)故事閱讀 39,919評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡蜡坊,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出秕衙,到底是詐尸還是另有隱情,我是刑警寧澤峡钓,帶...
    沈念sama閱讀 35,635評(píng)論 5 345
  • 正文 年R本政府宣布,位于F島的核電站能岩,受9級(jí)特大地震影響寞宫,放射性物質(zhì)發(fā)生泄漏拉鹃。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,237評(píng)論 3 329
  • 文/蒙蒙 一钥屈、第九天 我趴在偏房一處隱蔽的房頂上張望坝辫。 院中可真熱鬧,春花似錦近忙、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,855評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至拙友,卻和暖如春肯腕,著一層夾襖步出監(jiān)牢的瞬間钥平,已是汗流浹背实撒。 一陣腳步聲響...
    開封第一講書人閱讀 32,983評(píng)論 1 269
  • 我被黑心中介騙來泰國打工知态, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留立叛,地道東北人负敏。 一個(gè)月前我還...
    沈念sama閱讀 48,048評(píng)論 3 370
  • 正文 我出身青樓其做,卻偏偏與公主長得像,于是被迫代替她去往敵國和親妖泄。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,864評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,116評(píng)論 25 707
  • 作者:blue(又名一書and一世界) 我的github**用途: **當(dāng)作字典來查 some websites ...
    一書and一世界閱讀 1,196評(píng)論 2 19
  • 顯式動(dòng)畫 顯式動(dòng)畫,它能夠?qū)σ恍傩宰鲋付ǖ淖远x動(dòng)畫却汉,或者創(chuàng)建非線性動(dòng)畫荷并,比如沿著任意一條曲線移動(dòng)。 屬性動(dòng)畫 ...
    清風(fēng)沐沐閱讀 1,935評(píng)論 1 5
  • 今天下午去學(xué)校給大寶送東西既穆,大寶下了晚自習(xí)特意打過來電話問我是否到家,心中滿滿的感動(dòng)幻工。 兒子是典型...
    冰咖啡_4bf5閱讀 115評(píng)論 0 0
  • Une question, dans un studio ou autre en corée la télé, j...
    白天不賣豆腐閱讀 120評(píng)論 0 0