当前位置:首页 > VUE

vue实现凤凰效果

2026-01-15 23:11:37VUE

Vue 实现凤凰效果

凤凰效果通常指一种视觉动画,模拟凤凰展翅、火焰燃烧等动态效果。在 Vue 中实现这种效果,可以结合 CSS 动画、Canvas 或第三方动画库(如 GSAP)。以下是几种实现方式:

使用 CSS 动画实现火焰效果

通过 CSS 的 keyframestransform 属性模拟火焰动态效果。

vue实现凤凰效果

<template>
  <div class="phoenix-fire"></div>
</template>

<style>
.phoenix-fire {
  width: 100px;
  height: 100px;
  background: linear-gradient(to top, #ff3300, #ff9900);
  border-radius: 50%;
  animation: flicker 1s infinite alternate;
}

@keyframes flicker {
  0% { opacity: 0.8; transform: scale(1); }
  100% { opacity: 1; transform: scale(1.1); }
}
</style>

使用 Canvas 绘制凤凰动画

通过 Canvas 动态绘制凤凰的翅膀和火焰,结合 Vue 的生命周期控制动画。

vue实现凤凰效果

<template>
  <canvas ref="phoenixCanvas" width="400" height="400"></canvas>
</template>

<script>
export default {
  mounted() {
    const canvas = this.$refs.phoenixCanvas;
    const ctx = canvas.getContext('2d');
    let angle = 0;

    function drawPhoenix() {
      ctx.clearRect(0, 0, canvas.width, canvas.height);
      ctx.save();
      ctx.translate(200, 200);

      // 绘制翅膀
      ctx.beginPath();
      ctx.fillStyle = '#ff6600';
      ctx.arc(0, 0, 50, angle, angle + Math.PI * 1.5);
      ctx.fill();

      // 绘制火焰
      ctx.beginPath();
      ctx.fillStyle = '#ff3300';
      ctx.arc(0, 0, 30, angle + Math.PI, angle + Math.PI * 2);
      ctx.fill();

      ctx.restore();
      angle += 0.05;
      requestAnimationFrame(drawPhoenix);
    }
    drawPhoenix();
  }
};
</script>

使用 GSAP 实现高级动画

GSAP 是一个强大的动画库,适合实现复杂的凤凰展翅效果。

<template>
  <div ref="phoenix" class="phoenix"></div>
</template>

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

export default {
  mounted() {
    const phoenix = this.$refs.phoenix;
    gsap.to(phoenix, {
      scale: 1.2,
      duration: 1,
      repeat: -1,
      yoyo: true,
      ease: 'power1.inOut'
    });
  }
};
</script>

<style>
.phoenix {
  width: 100px;
  height: 100px;
  background: linear-gradient(to right, #ff6600, #ffcc00);
  border-radius: 50%;
}
</style>

使用 SVG 动画

SVG 的路径动画适合表现凤凰的飞行轨迹。

<template>
  <svg width="400" height="400">
    <path ref="phoenixPath" d="M100,100 C200,200 300,50 400,100" fill="none" stroke="#ff6600" stroke-width="2"/>
    <circle ref="phoenixBody" cx="100" cy="100" r="10" fill="#ff9900"/>
  </svg>
</template>

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

export default {
  mounted() {
    const phoenixBody = this.$refs.phoenixBody;
    const path = this.$refs.phoenixPath;
    const length = path.getTotalLength();

    gsap.to(phoenixBody, {
      motionPath: {
        path: path,
        align: path,
        alignOrigin: [0.5, 0.5]
      },
      duration: 3,
      repeat: -1,
      ease: 'none'
    });
  }
};
</script>

注意事项

  • 性能优化:Canvas 和 GSAP 适合复杂动画,但需注意频繁渲染的性能消耗。
  • 响应式设计:通过 Vue 的 computedwatch 动态调整动画参数以适应不同屏幕尺寸。
  • 浏览器兼容性:CSS 动画和 SVG 的兼容性较好,Canvas 和 GSAP 需测试目标环境。

标签: 凤凰效果
分享给朋友:

相关文章

vue实现突出效果

vue实现突出效果

Vue 实现突出效果的方法 在 Vue 中实现突出效果可以通过多种方式,包括动态样式绑定、过渡动画、第三方库等。以下是几种常见的方法: 动态样式绑定 通过 v-bind:class 或 v-bind…

css制作卷边效果

css制作卷边效果

使用伪元素和渐变实现卷边效果 通过CSS伪元素和线性渐变可以模拟纸张卷边的视觉效果。这种方法不需要额外元素,仅通过::before或::after伪元素实现。 .element { posit…

css3制作立体效果

css3制作立体效果

使用 transform 属性实现立体旋转 通过 transform-style: preserve-3d 和 rotateX/Y/Z 实现 3D 空间变换: .container { tr…

h5如何实现vr效果

h5如何实现vr效果

使用WebXR API实现VR效果 WebXR是浏览器中实现VR/AR的核心API,支持设备姿态追踪、渲染交互等功能。需在支持WebXR的设备(如Oculus、HTC Vive)或浏览器模拟环境中运行…

js实现滚动条效果

js实现滚动条效果

实现滚动条效果的方法 使用原生JavaScript实现滚动条 通过监听滚动事件,可以动态调整滚动条的位置和样式。以下是一个基础实现示例: // 获取DOM元素 const container =…

js实现图片滚动效果

js实现图片滚动效果

使用CSS动画实现图片滚动 通过CSS的@keyframes和animation属性实现无缝滚动效果。将图片容器设置为横向排列,通过动画平移位置。 <style> .scroll-c…