「HTML+CSS」自定義加載動(dòng)畫【036】
Part1效果展示

Part2Demo代碼
HTML
<!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">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<section><span></span></section>
</body>
</html>
CSS
html,body{
margin: 0;
height: 100%;
}
body{
display: flex;
justify-content: center;
align-items: center;
background: #263238;
}
section {
width: 650px;
height: 300px;
padding: 10px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
border: 2px solid red;
}
span {
width: 96px;
height: 96px;
border:10px solid;
background:rgba(255, 255, 255, .2) ;
border-color: white white transparent transparent;
border-radius: 50%;
position: relative;
display: flex;
justify-content: center;
align-items: center;
animation: rotation 2s ease-in-out infinite;
}
span::after{
content: '';
border: 24px solid;
border-color: red red transparent transparent;
border-radius: 50%;
}
@keyframes rotation {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg)
}
}
Part3原理詳解
步驟1
使用span標(biāo)簽,設(shè)置
寬度、高度均為96px 背景色:rgba(255, 255, 255, .2)
width: 96px;
height: 96px;
background: rgba(255, 255, 255, .2);
效果圖如下

步驟2
設(shè)置span邊框
邊框大?。?0px 形狀:直線 顏色:上/右邊框?yàn)榘咨?下/左邊框?yàn)橥该?/section>
效果圖如下

步驟3
對(duì)span設(shè)置flex布局,使得其中的元素上下左右居中
display: flex;
align-items: center;
justify-content: center;
步驟4
使用span::after偽類元素作為紅色部分
設(shè)置
邊框大小及形狀:24px solid 上/右邊框顏色為紅色 下/左邊框顏色為透明
border: 24px solid;
border-color: red red transparent transparent;
效果圖如下

步驟5
對(duì)span、span::after圓角化
border-radius: 50%;
效果圖如下

步驟6
為span添加動(dòng)畫
順時(shí)針旋轉(zhuǎn)(0-360度) 2s 無限循環(huán) 速度曲線:ease-in-out
animation: rotation 2s ease-in-out infinite;
@keyframes rotation {
0% {
transform: rotate(0deg)
}
100% {
transform: rotate(360deg)
}
}
效果圖如下

Part4結(jié)語
希望對(duì)您有所幫助
如有錯(cuò)誤歡迎小伙伴指正~
我是 海轟?(?ˊ?ˋ)?
如果您覺得寫得可以的話
請(qǐng)點(diǎn)個(gè)贊吧
謝謝支持??
評(píng)論
圖片
表情
