当前位置:首页 > VUE

vue实现凤凰效果

2026-01-15 23:11:37VUE

Vue 实现凤凰效果

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

使用 CSS 动画实现火焰效果

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

<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 的生命周期控制动画。

<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实现吸附效果的方法 吸附效果通常指页面滚动时,某个元素固定在特定位置(如顶部或底部)。以下是几种实现方式: 使用CSS的position: sticky 通过CSS的sticky定位实现吸附效…

css制作卷边效果

css制作卷边效果

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

vue实现对话框效果

vue实现对话框效果

Vue 对话框实现方法 使用组件化方式封装对话框 创建一个独立的对话框组件(如Dialog.vue),通过v-model控制显示隐藏: <template> <div cla…

js实现滚动条效果

js实现滚动条效果

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

vue实现tag效果

vue实现tag效果

实现基本标签结构 使用 Vue 的模板语法创建标签容器和单个标签元素。通过 v-for 动态渲染标签列表,结合 v-bind:key 确保渲染性能。 <template> &l…

vue实现折叠效果

vue实现折叠效果

使用 v-show 或 v-if 实现基础折叠 通过 Vue 的指令 v-show 或 v-if 控制元素的显示与隐藏。v-show 通过 CSS 的 display 属性切换,v-if 直接操作 D…