(-1)寫(xiě)在前面
?? 我用的是chrome49,這個(gè)idea是我在stackoverflow上回答問(wèn)題時(shí)看到了,多謝這位同行,加深了我對(duì)很多技術(shù)點(diǎn)的理解,最近剛到北京,忙碌了一兩天,在后續(xù)的日子里,會(huì)被安排面試,學(xué)習(xí)計(jì)劃只能按工作流走了,做完這個(gè)要看一個(gè)特別酷的效果,好激動(dòng)!
(0)效果演示
?
(1)實(shí)現(xiàn)方案
動(dòng)畫(huà)效果都是用animation做的
(2)知識(shí)點(diǎn)詳解
a. border-radius:40px;??
當(dāng)div的長(zhǎng)高都是80px的時(shí)候,div是一個(gè)圓形,其實(shí)長(zhǎng)高都是60px的時(shí)候也是圓型,同理都是40、30也是圓型,當(dāng)然案例中沒(méi)有使用這種方式。具體實(shí)現(xiàn)在代碼中說(shuō)明
b. position:absolute;
當(dāng)div使用此屬性時(shí),margin:0 auto是無(wú)效的,小球使用了這個(gè)屬性,他的水平居中的實(shí)現(xiàn)方式在代碼中說(shuō)明
立即學(xué)習(xí)“前端免費(fèi)學(xué)習(xí)筆記(深入)”;
c. animation:down 1.5s infinite alternate;
I.1.5s 是動(dòng)畫(huà)的持續(xù)時(shí)間,因?yàn)檠舆t時(shí)間出現(xiàn)在持續(xù)時(shí)間的后面,所以只出現(xiàn)一個(gè)帶s的參數(shù)是持續(xù)時(shí)間。
II.這里的alternate是指反向播放動(dòng)畫(huà),比如說(shuō)一個(gè)動(dòng)畫(huà)的幀如下
@keyframes down { from { … } 95% { … } to { … } }
正向播放是from-95-to,反向播放to-95%-from
d. @keyframes down{95%{…}}
如果對(duì)應(yīng)animate:down 1.5s;
動(dòng)畫(huà)在執(zhí)行到95%就到達(dá)了最終狀態(tài),剩余5%的時(shí)間會(huì)用在回到初始狀態(tài)。
(3)代碼加解釋
<!DOCTYPE html> <html> <head> <meta charset=utf-8> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> <title>為了生活</title> <style type="text/css"> * { margin:0; padding:0; } #lol { margin:0px auto; top:100px; width:80px; height:80px; background-color:red; border-radius:40px; position:absolute; left:160px; animation:down 1.5s infinite alternate; } @keyframes down { 95% { width:15px; height:15px; border-radius:7.5px; /*保證div始終是個(gè)圓形*/ top:300px; left:192.5px;/*保證小球始終水平居中*/ background:blue; } } #frame { width:400px; height:315px; margin:100px auto; border:1px red solid; position:relative; } #head { width:400px; height:100px; text-align:center; font-size:40px; font-weight:bold; line-height:100px; background-image:-webkit-linear-gradient(90deg, #be1e1e, #be9b1e, #1ebe21, #1ebeb5, #1e24be, #ba1ebe, #be1e1e); /*前面文章有提到*/ -webkit-background-clip: text;/*剪切背景顏色,只在文字上顯示*/ -webkit-text-fill-color:transparent;/*文字填充為透明色*/ background-size:100% 700%; /*前面文章有提到*/ animation:bc 6s infinite; } @keyframes bc { to { background-position:100% 100%; /*前面文章有提到*/ } } </style> <script type="text/javascript"> </script> </head <body> <div id="frame"> <div id="head">Animatiom</div> <div id="lol"></div> </div> </body> </html>
HTML怎么學(xué)習(xí)?HTML怎么入門(mén)?HTML在哪學(xué)?HTML怎么學(xué)才快?不用擔(dān)心,這里為大家提供了HTML速學(xué)教程(入門(mén)課程),有需要的小伙伴保存下載就能學(xué)習(xí)啦!
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://www.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)