当前位置:首页 > 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 需测试目标环境。

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

相关文章

jquery效果

jquery效果

jQuery 动画效果 jQuery 提供了多种内置动画效果,可用于实现平滑的页面交互。常用的方法包括 show()、hide()、toggle()、fadeIn()、fadeOut()、slideU…

vue实现效果展示

vue实现效果展示

Vue 实现效果展示的方法 Vue.js 提供了多种方式来实现动态效果展示,以下是一些常见的方法: 使用 Vue 的过渡和动画系统 Vue 内置了 <transition> 和 <…

vue实现弹窗效果

vue实现弹窗效果

使用 Vue 实现弹窗效果 组件化弹窗实现 创建独立的弹窗组件 Modal.vue,通过 v-if 或 v-show 控制显示状态: <template> <div class…

vue实现iframe效果

vue实现iframe效果

使用 Vue 实现 iframe 效果 在 Vue 中实现 iframe 效果可以通过直接使用 <iframe> 标签或结合动态绑定实现更灵活的功能。以下是几种常见方法: 基础 ifra…

vue实现滚动日志效果

vue实现滚动日志效果

实现滚动日志效果的基本思路 滚动日志效果通常指动态添加日志内容并自动滚动到底部,常见于实时日志监控或聊天界面。Vue中可通过以下方法实现: 使用v-for渲染日志列表 在Vue模板中使用v-for循…

vue 实现货架效果

vue 实现货架效果

实现货架效果的基本思路 货架效果通常指在网页中展示商品或物品的网格布局,可能包含拖拽排序、分类筛选、动画交互等功能。Vue.js 结合第三方库(如 vue-draggable 或 CSS Grid)可…