css vue vite实现闪烁的呼吸效果

效果如上所示:

代码如下所示

js 复制代码
<template>
  <div class="pulse-container">
    <!-- 核心小圆点 -->
    <div class="pulse-core"></div>

    <!-- 多重光环:3 层 -->
    <div
        v-for="(ring, index) in rings"
        :key="index"
        class="pulse-ring"
        :style="{
        width: ring.size + 'px',
        height: ring.size + 'px',
        backgroundColor: ring.color,
        boxShadow: `0 0 ${ring.blur}px ${ring.color}`,
        animationDelay: index * 0.06 + 's' /* 50px下,延迟极短,避免挤在一起 */
      }"
    ></div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const rings = ref([
  { size: 20, color: 'rgba(168, 71, 47, 0.85)', blur: 6 },
  { size: 35, color: 'rgba(210, 135, 115, 0.6)', blur: 12 },
  { size: 50, color: 'rgba(235, 190, 175, 0.3)', blur: 20 }
])
</script>

<style scoped>
.pulse-container {
  position: relative;
  width: 50px;
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.pulse-ring {
  position: absolute;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  /*
    总时长 1 秒
    使用 cubic-bezier(0.5, 0, 0.5, 1) 实现匀加速-匀减速对称
    让变大和变小看起来用时完全相等,节奏一致
  */
  animation: pulse-wave-symmetry 1s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

.pulse-core {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #4a1a10;
  z-index: 10;
  box-shadow: 0 0 4px rgba(74, 26, 16, 0.8);
  animation: core-pulse-symmetry 1s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

/* --- 完美对称的动画关键帧 --- */
/* 0% -> 50% 变大 (耗时 0.5s) */
/* 50% -> 100% 变小 (耗时 0.5s) */

@keyframes pulse-wave-symmetry {
  0% {
    transform: translate(-50%, -50%) scale(0);
    opacity: 1;
  }
  50% {
    /* 在此处达到最大,正好过去 0.5 秒 */
    transform: translate(-50%, -50%) scale(1.2);
    opacity: 0.5;
  }
  100% {
    /* 再过去 0.5 秒,回到起点 */
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
  }
}

/* 核心点的呼吸也完美对称 */
@keyframes core-pulse-symmetry {
  0% {
    transform: scale(0.8);
    opacity: 0.8;
  }
  50% {
    /* 在 0.5 秒时变大到最大 */
    transform: scale(1.1);
    opacity: 1;
  }
  100% {
    /* 1 秒时缩回最小 */
    transform: scale(0.8);
    opacity: 0.8;
  }
}
</style>
相关推荐
名字还没想好☜2 小时前
React 实现暗黑模式切换:localStorage 持久化、SSR 首屏闪烁与跟随系统主题
前端·javascript·react.js·ecmascript·react·next.js
自动化监测Learner3 小时前
主流 Web 端地图引擎对比:选型指南与优劣分析
javascript
计算机毕设定制辅导-无忧学长5 小时前
《基于SpringBoot青年公寓出租管理系统的设计与实现》
java·vue.js·spring boot·青年公寓出租管理系统
宿6747 小时前
vue3-config
前端·javascript·vue.js
梦醒沉醉8 小时前
4、CSS入门——属性选择器
css
ShineWinsu9 小时前
对于 Vue 3:从为什么学 Vue,到声明式渲染与数据响应式的解析
前端·javascript·vue.js
এ慕ོ冬℘゜10 小时前
样式控制 .css ()
前端·css
leoZ23111 小时前
第 6 篇:SchemaForm 渲染器核心实现
前端·javascript·vue.js·人工智能·神经网络·机器学习·自然语言处理
CoderYanger11 小时前
前端基础——JavaScript(基础语法)(下篇)
java·开发语言·前端·javascript·程序人生·面试·职场和发展
还是大剑师兰特11 小时前
vue项目浏览器版本判别,低于IE11跳转到新页面
前端·javascript·vue.js