vue实现底部波浪
Vue 实现底部波浪效果
在 Vue 中实现底部波浪效果,可以通过 SVG 或 CSS 绘制波浪形状。以下是两种常见方法:
SVG 波浪实现
使用 SVG 的 path 元素绘制波浪路径,通过 Vue 动态控制样式或动画:
<template>
<div class="wave-container">
<svg viewBox="0 0 1200 120" preserveAspectRatio="none">
<path
d="M0,0V46.29c47.79,22.2,103.59,32.17,158,28,70.36-5.37,136.33-33.31,206.8-37.5C438.64,32.43,512.34,53.67,583,72.05c69.27,18,138.3,24.88,209.4,13.08,36.15-6,69.85-17.84,104.45-29.34C989.49,25,1113-14.29,1200,52.47V0Z"
fill="currentColor"
opacity=".25"
class="wave-path"
></path>
<path
d="M0,0V15.81C13,36.92,27.64,56.86,47.69,72.05,99.41,111.27,165,111,224.58,91.58c31.15-10.15,60.09-26.07,89.67-39.8,40.92-19,84.73-46,130.83-49.67,36.26-2.85,70.9,9.42,98.6,31.56,31.77,25.39,62.32,62,103.63,73,40.44,10.79,81.35-6.69,119.13-24.28s75.16-39,116.92-43.05c59.73-5.85,113.28,22.88,168.9,38.84,30.2,8.66,59,6.17,87.09-7.5,22.43-10.89,48-26.93,60.65-49.24V0Z"
fill="currentColor"
class="wave-path"
></path>
</svg>
</div>
</template>
<style scoped>
.wave-container {
position: relative;
height: 150px;
width: 100%;
overflow: hidden;
color: #42b983; /* 波浪颜色 */
}
.wave-path {
animation: wave 8s linear infinite;
}
@keyframes wave {
0% { transform: translateX(0); }
100% { transform: translateX(-50%); }
}
</style>
CSS 波浪实现
使用纯 CSS 的 border-radius 和伪元素创建波浪效果:
<template>
<div class="wave"></div>
</template>
<style scoped>
.wave {
position: relative;
height: 70px;
width: 100%;
background: #42b983;
}
.wave::before {
content: "";
position: absolute;
left: 0;
bottom: 0;
right: 0;
background-repeat: repeat;
height: 10px;
background-size: 20px 20px;
background-image: radial-gradient(
circle at 10px -5px,
transparent 12px,
white 13px
);
}
.wave::after {
content: "";
position: absolute;
left: 0;
bottom: 0;
right: 0;
background-repeat: repeat;
height: 15px;
background-size: 40px 20px;
background-image: radial-gradient(
circle at 10px 15px,
white 12px,
transparent 13px
);
}
</style>
动态波浪高度
通过 Vue 的响应式数据控制波浪高度:
<template>
<div class="container">
<svg class="wave" :viewBox="`0 0 1200 ${waveHeight}`">
<path :d="wavePath" fill="#42b983"></path>
</svg>
</div>
</template>
<script>
export default {
data() {
return {
waveHeight: 120,
wavePath: 'M0,0V46.29c47.79,22.2,103.59,32.17,158,28...' // 完整路径
}
}
}
</script>
使用第三方库
安装 vue-waves 等专门库快速实现:
npm install vue-waves
<template>
<vue-waves :color="waveColor" :height="waveHeight"/>
</template>
<script>
import VueWaves from 'vue-waves';
export default {
components: { VueWaves },
data() {
return {
waveColor: '#42b983',
waveHeight: 100
}
}
}
</script>
关键点:
- SVG 路径可通过在线工具生成(如 getwaves.io)
- 动画效果通过 CSS
transform或animation实现 - 响应式设计需考虑
viewBox和容器尺寸的适配







