当前位置:首页 > VUE

vue实现扩散圆

2026-02-11 10:14:00VUE

Vue 实现扩散圆效果

扩散圆效果通常用于视觉焦点提示或动画过渡,可以通过 Vue 结合 CSS 动画实现。以下是两种常见实现方式:

使用纯 CSS 动画

通过 Vue 控制 CSS 类名的切换触发动画:

<template>
  <div class="circle-container">
    <div 
      class="circle" 
      :class="{ 'expand': isExpanding }"
      @click="toggleAnimation"
    ></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isExpanding: false
    }
  },
  methods: {
    toggleAnimation() {
      this.isExpanding = true;
      setTimeout(() => {
        this.isExpanding = false;
      }, 1000);
    }
  }
}
</script>

<style>
.circle {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: #42b983;
  position: relative;
  transition: all 0.5s ease;
}

.circle.expand {
  transform: scale(2);
  opacity: 0;
}
</style>

使用 GSAP 实现高级动画

安装 GSAP 库后实现更复杂的扩散效果:

npm install gsap
<template>
  <div class="circle-container">
    <div 
      ref="circle"
      class="circle"
      @click="animateCircle"
    ></div>
  </div>
</template>

<script>
import { gsap } from 'gsap';

export default {
  methods: {
    animateCircle() {
      gsap.to(this.$refs.circle, {
        scale: 3,
        opacity: 0,
        duration: 1,
        ease: "power2.out",
        onComplete: () => {
          gsap.set(this.$refs.circle, { scale: 1, opacity: 1 });
        }
      });
    }
  }
}
</script>

<style>
.circle {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: #42b983;
  cursor: pointer;
}
</style>

多层波纹扩散效果

实现类似水波纹的多层扩散效果:

<template>
  <div class="container">
    <div 
      v-for="(wave, index) in waves"
      :key="index"
      class="wave"
      :style="{
        width: `${wave.size}px`,
        height: `${wave.size}px`,
        left: `-${wave.size/2 - 25}px`,
        top: `-${wave.size/2 - 25}px`,
        opacity: wave.opacity
      }"
    ></div>
    <div class="center-circle" @click="createWave"></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      waves: [],
      maxWaves: 3
    }
  },
  methods: {
    createWave() {
      if (this.waves.length >= this.maxWaves) return;

      const newWave = {
        size: 50,
        opacity: 0.7
      };

      this.waves.push(newWave);

      const interval = setInterval(() => {
        newWave.size += 5;
        newWave.opacity -= 0.02;

        if (newWave.opacity <= 0) {
          clearInterval(interval);
          this.waves = this.waves.filter(w => w !== newWave);
        }
      }, 30);
    }
  }
}
</script>

<style>
.container {
  position: relative;
  width: 100px;
  height: 100px;
  margin: 50px;
}

.center-circle {
  position: absolute;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: #42b983;
  cursor: pointer;
  z-index: 10;
}

.wave {
  position: absolute;
  border-radius: 50%;
  background-color: #42b983;
  transform-origin: center;
  transition: opacity 0.1s;
}
</style>

这些实现方式可以根据具体需求进行调整,如修改颜色、大小、动画时长等参数。对于更复杂的效果,可以结合 SVG 或 Canvas 实现。

vue实现扩散圆

标签: vue
分享给朋友:

相关文章

vue实现div

vue实现div

Vue 实现 DIV 元素的方法 在 Vue 中实现 DIV 元素可以通过多种方式,以下是几种常见的实现方法: 使用模板语法 在 Vue 的模板中直接使用 HTML 的 <div> 标签…

vue 实现豆瓣

vue 实现豆瓣

以下是基于 Vue 实现豆瓣电影类功能的实现方案,涵盖核心模块和技术要点: 数据获取与 API 调用 使用豆瓣开放 API(需注意调用频率限制)或第三方代理接口 推荐 axios 进行异步请求,配…

vue 实现关闭

vue 实现关闭

Vue 实现关闭功能的方法 在Vue中实现关闭功能通常涉及组件销毁、模态框隐藏或路由跳转等场景。以下是几种常见实现方式: 销毁当前组件 使用v-if或v-show控制组件显示/隐藏,适用于局部组件:…

vue实现表白

vue实现表白

Vue 实现表白页面 使用 Vue 可以快速创建一个动态、交互式的表白页面。以下是一个简单的实现方案: 基础结构 创建一个 Vue 项目或单文件组件,包含以下核心部分: <templat…

vue实现试卷

vue实现试卷

Vue实现试卷系统的基本思路 使用Vue.js构建试卷系统需要结合组件化开发、状态管理和后端数据交互。核心功能包括题目展示、答题逻辑、计时器和提交答案。 核心功能模块划分 试卷组件结构 试卷容器组…

vue拖拽实现

vue拖拽实现

Vue 拖拽实现方法 使用 HTML5 原生拖拽 API HTML5 提供了原生拖拽 API,可以通过 draggable 属性、dragstart、dragend、dragover 和 drop 事…