前言
Hello列粪!小伙伴!
首先非常感謝您閱讀海轟的文章憨栽,倘若文中有錯誤的地方输钩,歡迎您指出~
哈哈 自我介紹一下
昵稱:海轟
標(biāo)簽:程序猿一只|C++選手|學(xué)生
簡介:因C語言結(jié)識編程,隨后轉(zhuǎn)入計算機(jī)專業(yè)赏陵,有幸拿過國獎饼齿、省獎等,已保研蝙搔。目前正在學(xué)習(xí)C++/Linux(真的真的太難了~)
學(xué)習(xí)經(jīng)驗:扎實基礎(chǔ) + 多做筆記 + 多敲代碼 + 多思考 + 學(xué)好英語缕溉!
效果展示
css-自定義加載動畫6.gif
思路
這里用span元素代表外層白色圓圈
兩個紅色小球分別用span的兩個偽類::before和::after代表
根據(jù)效果圖,可以大概得出思路
- 先利用span生成一個正方形吃型,設(shè)置好邊框
- 兩個偽類元素為絕對定位证鸥,分別位于正方形的左上和右下
- 然后分別對其進(jìn)行圓角處理
- 最后添加旋轉(zhuǎn)動畫即可
Demo代碼
HTML
<!DOCTYPE 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 white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
position: relative;
animation: rotation 2s linear infinite;
}
span::before{
position: absolute;
content: '';
top: 15px;
left: 15px;
width: 20px;
height: 20px;
background: red;
border-radius: 50%;
}
span::after{
position: absolute;
content: '';
bottom: 15px;
right: 15px;
width: 20px;
height: 20px;
background: red;
border-radius: 50%;
}
@keyframes rotation {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg)
}
}
原理詳解
步驟1
將span元素設(shè)置為
- 一個96??96px的正方形
- 邊框為10px,白色勤晚,solid
width : 96px;
height: 96px;
border: 10px solid #fff;
效果圖如下
在這里插入圖片描述
步驟2
span::before和span::after設(shè)置
- 寬度枉层、高度均為20px
- 絕對定位,其中before位于左上赐写,after位于右下
- 背景色為紅色
/* before的設(shè)置*/
position: absolute;
content: '';
top: 0;
left: 0;
width: 20px;
height: 20px;
background: red;
/*after的設(shè)置*/
position: absolute;
content: '';
bottom: 0;
right: 0;
width: 20px;
height: 20px;
background: red;
效果圖如下
在這里插入圖片描述
步驟3
稍微向正方形中心移動下::before和::after
/* before的設(shè)置*/
top: 15px;
left: 15px;
/*after的設(shè)置*/
bottom: 15px;
right: 15px;
效果圖如下
在這里插入圖片描述
步驟4
對span鸟蜡、span::before、span::after設(shè)置圓角
border-radius: 50%;
效果圖如下
在這里插入圖片描述
步驟7
為span添加動畫
animation: rotation 1s linear infinite;
/*動畫實現(xiàn)*/
@keyframes rotation {
0% { transform: rotate(0deg) }
100% { transform: rotate(360deg)
}
效果圖如下
css-自定義加載動畫6.gif
結(jié)語
學(xué)習(xí)來源:
文章僅作為學(xué)習(xí)筆記血淌,記錄從0到1的一個過程矩欠。希望對您有所幫助财剖,如有錯誤歡迎小伙伴指正~
我是海轟?(?ˊ?ˋ)?,如果您覺得寫得可以的話癌淮,請點個贊吧
寫作不易躺坟,「點贊」+「收藏」+「轉(zhuǎn)發(fā)」
謝謝支持??
在這里插入圖片描述