日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > CSS >内容正文

CSS

如何用纯 CSS 创作一个荧光脉冲 loader 特效

發(fā)布時(shí)間:2025/3/20 CSS 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何用纯 CSS 创作一个荧光脉冲 loader 特效 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

效果預(yù)覽

在線演示

按下右側(cè)的“點(diǎn)擊預(yù)覽”按鈕在當(dāng)前頁(yè)面預(yù)覽,點(diǎn)擊鏈接全屏預(yù)覽。

https://codepen.io/zhang-ou/pen/erRzzR

可交互視頻教程

此視頻是可以交互的,你可以隨時(shí)暫停視頻,編輯視頻中的代碼。

請(qǐng)用 chrome, safari, edge 打開(kāi)觀看。

https://scrimba.com/c/cwrJys7

源代碼下載

本地下載

請(qǐng)從 github 下載。

https://github.com/comehope/front-end-daily-challenges/tree/master/011-ripple-pulse-loader-animation

代碼解讀

定義 dom,只有一個(gè)元素:

<div class="circle"></div>

居中顯示:

html, body, .circle {height: 100%;display: flex;align-items: center;justify-content: center;background-color: black; }

畫(huà)出中間的實(shí)心圓:

:root {--innerRadius: 2em; }.circle {width: calc(var(--innerRadius) * 2);height: calc(var(--innerRadius) * 2);background-color: lime;border-radius: 50%; }

畫(huà)出圓環(huán):

.circle {box-shadow: 0 0 0 calc(var(--innerRadius) - 0.4em) black,0 0 0 var(--innerRadius) lime; }

用偽元素 ::before 畫(huà)出動(dòng)畫(huà)用到的圓環(huán):

.circle::before {content: '';position: absolute;width: calc(var(--innerRadius) * 2 * 2);height: calc(var(--innerRadius) * 2 * 2);border: 2px solid lime;border-radius: 50%; }

增加動(dòng)畫(huà)效果:

.circle::beforeanimation: pulse 2s linear infinite; }@keyframes pulse {from {transform: scale(1);}to {transform: scale(2);} }

優(yōu)化動(dòng)畫(huà)——增加漸淡和彈性效果:

.circle::beforeanimation: pulse 2s ease-out infinite; }@keyframes pulse {from {filter: opacity(0.9);}to {filter: opacity(0);} }

最后,用偽元素 ::after 再畫(huà)出一個(gè)動(dòng)的圓環(huán):

.circle::after {content: '';position: absolute;width: calc(var(--innerRadius) * 2 * 2);height: calc(var(--innerRadius) * 2 * 2);border: 2px solid lime;border-radius: 50%;animation: pulse 2s ease-out infinite; }.circle::after {animation-delay: 1s; }

大功告成!

知識(shí)點(diǎn)

  • variables https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Variables
  • calc() https://developer.mozilla.org/en-US/docs/Web/CSS/calc
  • animation-timing-function https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timing-function
  • filter https://developer.mozilla.org/en-US/docs/Web/CSS/filter#Functions
  • box-shadow https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow

原文地址:https://segmentfault.com/a/1190000014700727

總結(jié)

以上是生活随笔為你收集整理的如何用纯 CSS 创作一个荧光脉冲 loader 特效的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。