简单脉冲动画效果实现

简单脉冲动画效果实现

效果展示

CSS 知识点

  • CSS 变量的灵活使用
  • CSS 动画使用

页面整体结构实现

html 复制代码
<div class="pulse">
  <span style="--i: 1"></span>
  <span style="--i: 2"></span>
  <span style="--i: 3"></span>
  <span style="--i: 4"></span>
  <span style="--i: 5"></span>
  <span style="--i: 6"></span>
</div>

实现整体布局

css 复制代码
.pulse {
  position: relative;
  width: 200px;
  height: 200px;
  box-shadow: inset 0 0 40px #12b9ff, 0 0 50px #12b9ff;
  border-radius: 50%;
  border: 1px solid #12b9ff;
  background: url(./earch.jpg);
  background-size: cover;
}

.pulse span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: transparent;
  border: 1px solid #12b9ff;
  border-radius: 50%;
}

使用CSS变量和动画实现脉冲效果

css 复制代码
.pulse span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: transparent;
  border: 1px solid #12b9ff;
  animation: animate 6s linear infinite;
  border-radius: 50%;
  animation-delay: calc(var(--i) * -1s);
}

@keyframes animate {
  0%{
    width: 200px;
    height: 200px;
    opacity: 1;
  }
  50% {
    opacity: 1;
  }
  100% {
    width: 600px;
    height: 600px;
    opacity: 0;
  }
}

实现地球运动效果

css 复制代码
.pulse {
  position: relative;
  width: 200px;
  height: 200px;
  box-shadow: inset 0 0 40px #12b9ff, 0 0 50px #12b9ff;
  border-radius: 50%;
  border: 1px solid #12b9ff;
  background: url(./earch.jpg);
  background-size: cover;
  animation: animateEarth 30s linear infinite;
}

@keyframes animateEarth {
  0% {
    background-position-x: 0px;
  }
  100% {
    background-position-x: 2400px;
  }
}

完整代码下载

完整代码下载

相关推荐
FRing034 小时前
vue3干货总结3(defineOptions(Vue3.3)、defineModel(Vue3.4)、Pinia)
开发语言·前端·vue.js·vue3
Bczheng14 小时前
组件化服务端渲染模式SSR
前端
whitelbwwww5 小时前
CUDA C++实战--中级
开发语言·前端·c++
张紫娃5 小时前
Chrome插件-Stylus(屏蔽博客广告)
前端·chrome·stylus
Yannik6 小时前
在 Apple Silicon Mac 上用 Jenkins + Fastlane 搭建 iOS CI:从自动打包到 MR 检查流水线的完整实践
前端
Nayana6 小时前
《Web 到 HarmonyOS》-- 打包:Vite 产物 → HAP / HAR / HSP
前端
inksci6 小时前
用飞帆做了个小网页
前端·javascript·css·html
去伪存真6 小时前
被 pnpm 打包坑惨后,我彻底盘明白了硬链接与软链接
前端·electron
zhensherlock7 小时前
Protocol Launcher 系列:CodeHub 移动端 GitHub 协作利器
前端·javascript·typescript·node.js·自动化·github·js
tryCbest12 小时前
Vue3——第 22 篇:Pinia——新一代状态管理(上)
前端·javascript·vue.js