vue实现领奖台
Vue 实现领奖台效果
领奖台效果通常用于展示排名前三的用户或项目,可以通过 Vue 的动态绑定和样式控制来实现。
基本结构
使用 Vue 的模板语法构建领奖台的基本 HTML 结构,包含三个台阶(金牌、银牌、铜牌)。
<template>
<div class="podium">
<div class="podium-step silver" :style="{ height: heights[1] + 'px' }">
<div class="position">2</div>
<div class="name">{{ names[1] }}</div>
</div>
<div class="podium-step gold" :style="{ height: heights[0] + 'px' }">
<div class="position">1</div>
<div class="name">{{ names[0] }}</div>
</div>
<div class="podium-step bronze" :style="{ height: heights[2] + 'px' }">
<div class="position">3</div>
<div class="name">{{ names[2] }}</div>
</div>
</div>
</template>
数据绑定
通过 Vue 的 data 或 props 动态绑定领奖台的高度和名称。
<script>
export default {
data() {
return {
heights: [200, 150, 100], // 金牌、银牌、铜牌的高度
names: ['冠军', '亚军', '季军'] // 对应的名称
};
}
};
</script>
样式设计
使用 CSS 设置领奖台的样式,包括颜色、间距和动画效果。
<style scoped>
.podium {
display: flex;
align-items: flex-end;
justify-content: center;
gap: 10px;
margin-top: 20px;
}
.podium-step {
width: 100px;
display: flex;
flex-direction: column;
align-items: center;
transition: height 0.5s ease;
}
.gold {
background-color: gold;
}
.silver {
background-color: silver;
}
.bronze {
background-color: #cd7f32; /* 古铜色 */
}
.position {
font-size: 24px;
font-weight: bold;
margin-bottom: 10px;
}
.name {
font-size: 16px;
}
</style>
动态更新
如果需要动态更新领奖台数据,可以通过方法或计算属性实现。
methods: {
updatePodium(newNames, newHeights) {
this.names = newNames;
this.heights = newHeights;
}
}
动画效果
通过 Vue 的过渡或 CSS 动画增强交互体验。
.podium-step {
transition: height 0.5s ease, transform 0.3s ease;
}
.podium-step:hover {
transform: translateY(-5px);
}
完整示例
以下是一个完整的 Vue 单文件组件示例:
<template>
<div class="podium">
<div class="podium-step silver" :style="{ height: heights[1] + 'px' }">
<div class="position">2</div>
<div class="name">{{ names[1] }}</div>
</div>
<div class="podium-step gold" :style="{ height: heights[0] + 'px' }">
<div class="position">1</div>
<div class="name">{{ names[0] }}</div>
</div>
<div class="podium-step bronze" :style="{ height: heights[2] + 'px' }">
<div class="position">3</div>
<div class="name">{{ names[2] }}</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
heights: [200, 150, 100],
names: ['冠军', '亚军', '季军']
};
},
methods: {
updatePodium(newNames, newHeights) {
this.names = newNames;
this.heights = newHeights;
}
}
};
</script>
<style scoped>
.podium {
display: flex;
align-items: flex-end;
justify-content: center;
gap: 10px;
margin-top: 20px;
}
.podium-step {
width: 100px;
display: flex;
flex-direction: column;
align-items: center;
transition: height 0.5s ease, transform 0.3s ease;
}
.gold {
background-color: gold;
}
.silver {
background-color: silver;
}
.bronze {
background-color: #cd7f32;
}
.position {
font-size: 24px;
font-weight: bold;
margin-bottom: 10px;
}
.name {
font-size: 16px;
}
.podium-step:hover {
transform: translateY(-5px);
}
</style>
扩展功能
- 数据动态加载:通过 API 获取领奖台数据并动态更新。
- 响应式设计:使用媒体查询适配不同屏幕尺寸。
- 交互效果:点击领奖台显示详细信息或触发其他动作。







