效果展示
css-自定義加載動畫4.gif
Demo代碼
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 #fff;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
position: relative;
animation: rotation 1s linear infinite;
}
span::after{
position: relative;
content: '';
display: inline-block;
width: 72px;
height: 72px;
border-radius: 50%;
border: 10px solid transparent;
border-bottom-color: #FF3D00;
border-top-color: #FF3D00;
}
@keyframes rotation {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg)
}
}
原理解釋
動畫的核心部分就是span和span::after容贝,section僅作為提示框比然。
步驟1
將span元素設(shè)置為
- 一個96??96px的正方形
- 邊框為10px唧龄,白色,solid
width : 96px;
height: 96px;
border: 10px solid #fff;
效果圖如下
在這里插入圖片描述
步驟2
span::after偽元素設(shè)置為:
- 位于span正中
- 邊長72??72px的正方形
注:紅色部分即為span::after测蘑,為便于觀察才設(shè)置為紅色
在這里插入圖片描述
步驟3
span::after設(shè)置
- 下邊框:10px 紅色 solid
- 上邊框:10px 紅色 solid
- 左/右邊框:10px 透明 solid
border: 10px solid transparent;
border-bottom-color: #FF3D00;
border-top-color: #FF3D00;
在這里插入圖片描述
步驟4
span和span::after
- border-radius均設(shè)置為50%
border-radius: 50%;
效果圖如下
在這里插入圖片描述
步驟5
為span添加動畫
animation: rotation 1s linear infinite;
/*動畫實現(xiàn)*/
@keyframes rotation {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg)
}
效果圖如下
css-自定義加載動畫4.gif
結(jié)語
學(xué)習來源:
主要學(xué)會思路,弄清楚效果是如何實現(xiàn)的康二,然后再根據(jù)自己的理解再敲一遍代碼碳胳,一定要敲!
文章僅作為學(xué)習筆記沫勿,記錄從0到1的一個過程挨约。希望對您有所幫助,如有錯誤歡迎小伙伴指正~
我是海轟?(?ˊ?ˋ)?产雹,如果您覺得寫得可以的話诫惭,請點個贊吧
寫作不易,「點贊」+「收藏」+「轉(zhuǎn)發(fā)」
謝謝支持??
在這里插入圖片描述