前言
Hello!小伙伴!
首先非常感謝您閱讀海轟的文章,倘若文中有錯誤的地方,歡迎您指出~
哈哈 自我介紹一下
昵稱:海轟
標簽:程式猿一只|C++選手|學生
簡介:因C語言結識編程,隨后轉入計算機專業,有幸拿過國獎、省獎等,已保研,目前正在學習C++/Linux(真的真的太難了~)
學習經驗:扎實基礎 + 多做筆記 + 多敲代碼 + 多思考 + 學好英語!
日常分享:微信公眾號【海轟Pro】記錄生活、學習點滴,分享一些源代碼或者學習資料,歡迎關注~
效果展示

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="https://www.cnblogs.com/haihongpro/archive/2021/04/22/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;
position: relative;
}
span::before,
span::after{
content: '';
width : 76px;
height: 76px;
position: absolute;
top: 0;
left: 0;
border-radius: 50%;
border:10px solid white;
animation: animloader 2s linear infinite;
}
span::after{
animation-delay: 1s;
}
@keyframes animloader {
0% { transform: scale(0); opacity: 1;
}
100% { transform: scale(1); opacity: 0;}
}
原理詳解
步驟1
設定span標簽
- 寬度、高度均為96px
- 相對定位
width : 96px;
height: 96px;
position: relative;
因為未設定背景色(這里不需要背景色)
所以視覺上看不見

實際效果如下

步驟2
設定span::befor、span::after
- 寬度、高度均為76px
- 邊框:10px 白色 solid
- 絕對定位:top0 left0
因為before和after位置重疊
視覺上看起來就只有一個白色部分

實際上是有兩個部分的


步驟3
span::before、span::after圓角化
border-radius: 50%;
效果圖如下

步驟4
為span::before、span::after添加影片
- 影片時間:2s
- 影片速度曲線:linear
- 無限回圈
- 影片初態:大小0,不透明級別為1(也就是開始沒有,但是顏色不透明級別為1,純白)
- 影片末態:大小為1,也就是正常大小,不透明級別為1,此時已經看不見了
- 形成的影片就是:一個圓大小上從小到大,顏色從純白色,漸漸透明
animation: animloader 2s linear infinite;
@keyframes animloader {
0% { transform: scale(0); opacity: 1;
}
100% { transform: scale(1); opacity: 0;}
}
效果圖如下

步驟5
步驟1-4形成的表面上只是一個圓的變化效果
其實是span::before和span::after兩個圓同時的影片
只是因為位置重疊 看起來就是一個圓了
然后我們再對span::after使用影片延遲
使之與span::before視覺上分開
這樣同一時間就可以得到類似水波紋的效果啦
animation-delay: 1s;
效果圖如下

結語
學習來源:
https://codepen.io/bhadupranjal/pen/vYLZYqQ
文章僅作為學習筆記,記錄從0到1的一個程序,希望對您有所幫助,如有錯誤歡迎小伙伴指正~
我是海轟?(?ˊ?ˋ)?,如果您覺得寫得可以的話,請點個贊吧
寫作不易,「點贊」+「收藏」+「轉發」
謝謝支持??

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/279220.html
標籤:其他
上一篇:js利用Image物件賦值src,將圖片快取到瀏覽器
下一篇:前端?規模構建演進實踐
