哈嘍!俺又來了,馬上就要8月份了,時間仿佛在對我說:“暑假?拿來吧你”🙃又是學習css和js的一天,在刷小視頻加載時經常看到一些加載影片,簡單上手了css3新增的影片后,就想仿寫一個加載效果,就是玩哈哈,開整!

效果:

1. 分析元素
可以看到這個簡單的特效由5個塊通過延時差形成的,能給人一種再等等的想法,很不錯,設計yyds,
5個塊我們用5個盒子實作,配合CSS3的影片關鍵幀以及偽類選擇器實作延時差即可實作,有一個好的分析和思路,可以減少你的coding出錯率和time,🆗,coding吧!!!
2.html部分
這就是爸爸管著5個兒子,不用多說了
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>加載影片</title>
</head>
<body>
<div class="box">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
</html>
3.CSS部分
CSS3的結構偽類選擇器控制 匹配除了第一個以外的兒子,延時產生感覺,哈哈,為啥不可以直接寫在一個里好比.box>div:nth-child(2,3,4,5){ animation-delay: -1s; }不懂,可能還需要完善吧!我是這樣想的
.box{
margin: 200px auto;
width: 50px;
height: 50px;
text-align: center;
font-size: 10px;
}
.box > div{
background-color: rgba(64, 219, 25,0.9);
width: 5px;
height: 100%;
/* 行內塊 */
display: inline-block;
/* 名字 執行時間 一直執行 先慢再快再慢 */
animation: move 1.2s infinite ease-in-out;
}
/* 定義關鍵幀 */
@keyframes move{
0%{transform: scaleY(0.4);}
40%{transform: scaleY(0.4);}
60%{transform: scaleY(0.4);}
80%{transform: scaleY(0.4);}
100%{transform: scaleY(0.4);}
20%{transform: scaleY(1);}
}
/* 偽類選擇器控制 匹配除了第一個以外的兒子,延時產生感覺*/
.box>div:nth-child(2){
animation-delay: -1s;
}
.box>div:nth-child(3){
animation-delay: -0.9s;
}
.box>div:nth-child(4){
animation-delay: -0.8s;
}
.box>div:nth-child(5){
animation-delay: -0.7s;
}
4.完整代碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>加載影片</title>
<style>
.box{
margin: 200px auto;
width: 50px;
height: 50px;
text-align: center;
font-size: 10px;
}
.box > div{
background-color: rgba(64, 219, 25,0.9);
width: 5px;
height: 100%;
/* 行內塊 */
display: inline-block;
/* 名字 執行時間 一直執行 先慢再快再慢 */
animation: move 1.2s infinite ease-in-out;
}
/* 定義關鍵幀 */
@keyframes move{
0%{transform: scaleY(0.4);}
40%{transform: scaleY(0.4);}
60%{transform: scaleY(0.4);}
80%{transform: scaleY(0.4);}
100%{transform: scaleY(0.4);}
20%{transform: scaleY(1);}
}
.box>div:nth-child(2){
animation-delay: -1s;
}
.box>div:nth-child(3){
animation-delay: -0.9s;
}
.box>div:nth-child(4){
animation-delay: -0.8s;
}
.box>div:nth-child(5){
animation-delay: -0.7s;
}
</style>
</head>
<body>
<div class="box">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
</html>
是不是很簡單,寫京東的專案受到打擊了,還是慢慢來吧!是要有一個程序的,加油~🆗,就到這,下課,拜拜了你!

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/290923.html
標籤:其他
