简单脉冲动画效果实现

简单脉冲动画效果实现

效果展示

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;
  }
}

完整代码下载

完整代码下载

相关推荐
coderYYY7 分钟前
element树结构el-tree,默认选中当前setCurrentKey无效
前端·javascript·vue.js
GISer_Jing37 分钟前
[总结篇]个人网站
前端·javascript
lljss202044 分钟前
html文字红色粗体,闪烁渐变动画效果,中英文切换版本
css·html·css3
疯狂的沙粒1 小时前
在web-view 加载的本地及远程HTML中调用uniapp的API及网页和vue页面是如何通讯的?
前端·uni-app·html
小妖6661 小时前
html 滚动条滚动过快会留下边框线
前端·html
heroboyluck1 小时前
Svelte 核心语法详解:Vue/React 开发者如何快速上手?
前端·svelte
海的诗篇_1 小时前
前端开发面试题总结-JavaScript篇(二)
开发语言·前端·javascript·typescript
琹箐1 小时前
ant-design4.xx实现数字输入框; 某些输入法数字需要连续输入两次才显示
前端·javascript·anti-design-vue
程序员-小李1 小时前
VuePress完美整合Toast消息提示
前端·javascript·vue.js
Uyker2 小时前
从零开始制作小程序简单概述
前端·微信小程序·小程序