当前位置:首页 > 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 的路径动画适合表现凤凰的飞行轨迹。

vue实现凤凰效果

<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 需测试目标环境。

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

相关文章

js实现滚动条效果

js实现滚动条效果

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

vue实现基金效果

vue实现基金效果

Vue 实现基金效果 在 Vue 中实现基金效果,通常指的是模拟基金的增长、波动或可视化展示。以下是几种常见的实现方式: 数据绑定与动态更新 通过 Vue 的数据绑定特性,可以动态展示基金净值的变化…

vue实现tag效果

vue实现tag效果

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

vue实现翻书效果

vue实现翻书效果

Vue实现翻书效果的方法 翻书效果可以通过CSS动画和Vue的动态绑定实现,以下是几种常见的实现方式: 使用CSS transform和transition 通过CSS的transform属…

react如何添加效果

react如何添加效果

React 添加动画效果的方法 使用 CSS 过渡动画 在 React 组件中直接通过 className 或 style 属性应用 CSS 过渡效果。定义 CSS 类包含 transition 属性…

vue实现侧滑效果

vue实现侧滑效果

实现侧滑效果的方法 使用Vue的过渡动画 在Vue中可以通过<transition>组件结合CSS过渡实现侧滑效果。定义一个滑动动画类,控制元素的transform属性。 <tem…