vue实现冰墩墩
Vue 实现冰墩墩动画效果
使用 Vue 结合 CSS 动画和 SVG 可以实现冰墩墩的动画效果。以下是一个简单的实现方法:
创建 Vue 组件
<template>
<div class="bing-dwen-dwen">
<svg viewBox="0 0 200 200" class="dwen-animation">
<!-- 冰墩墩身体轮廓 -->
<path d="M100,50 Q150,80 100,150 Q50,80 100,50" fill="#29B6F6" />
<!-- 眼睛 -->
<circle cx="80" cy="80" r="10" fill="white" />
<circle cx="120" cy="80" r="10" fill="white" />
<!-- 黑色眼珠 -->
<circle cx="80" cy="80" r="5" fill="black" />
<circle cx="120" cy="80" r="5" fill="black" />
<!-- 嘴巴 -->
<path d="M90,110 Q100,120 110,110" stroke="black" fill="none" />
</svg>
</div>
</template>
<script>
export default {
name: 'BingDwenDwen'
}
</script>
<style>
.bing-dwen-dwen {
width: 300px;
height: 300px;
margin: 0 auto;
}
.dwen-animation {
animation: bounce 2s infinite alternate;
}
@keyframes bounce {
from {
transform: translateY(0);
}
to {
transform: translateY(-20px);
}
}
</style>
添加更复杂的动画效果
可以通过组合多个 CSS 动画实现更生动的效果:
.dwen-animation {
animation:
bounce 2s infinite alternate,
blink 4s infinite;
}
@keyframes blink {
0%, 48%, 52%, 100% {
transform: scaleY(1);
}
50% {
transform: scaleY(0.1);
}
}
使用 GSAP 实现高级动画
安装 GSAP 库:
npm install gsap
在组件中使用:
<script>
import { gsap } from 'gsap'
export default {
name: 'BingDwenDwen',
mounted() {
gsap.to(".dwen-animation", {
y: -20,
duration: 1,
repeat: -1,
yoyo: true,
ease: "sine.inOut"
})
}
}
</script>
添加冬奥会元素
可以在冰墩墩周围添加冬奥会相关元素:

<template>
<div class="winter-olympics">
<svg viewBox="0 0 300 300">
<!-- 雪花背景 -->
<circle cx="50" cy="50" r="5" fill="white" />
<circle cx="250" cy="100" r="5" fill="white" />
<!-- 冰墩墩 -->
<g transform="translate(100, 50)" class="dwen-animation">
<!-- 冰墩墩SVG路径 -->
</g>
</svg>
</div>
</template>
这些方法可以根据需要组合使用,创造出不同复杂度的冰墩墩动画效果。






