uniapp 卡片式轮播图
时间: 2025-01-10 21:54:27 浏览: 61
### 如何在 UniApp 中创建卡片式轮播图
为了实现在 UniApp 应用程序中的卡片式轮播图效果,可以采用 `swiper` 组件并自定义样式来达到目的。下面提供了一个具体的实例说明。
#### 创建 Swiper 卡片布局
通过设置 swiper 的属性以及利用 CSS 来调整滑动项的位置和大小,从而形成卡片式的视觉体验:
```html
<template>
<view class="container">
<!-- Swiper 容器 -->
<swiper :indicator-dots="true" :autoplay="false" circular interval="5000" duration="300" @change="handleChange">
<swiper-item v-for="(item, index) in cardList" :key="index">
<view :class="'card ' + (current === index ? 'active' : '')">
{{ item.title }}
</view>
</swiper-item>
</swiper>
</view>
</template>
<script>
export default {
data() {
return {
current: 0,
cardList: [
{ title: "Card One", id: 1 },
{ title: "Card Two", id: 2 },
{ title: "Card Three", id: 3 }
]
};
},
methods: {
handleChange(e) {
this.current = e.detail.current;
}
}
};
</script>
<style scoped>
/* 自定义样式 */
.card {
width: 80%;
height: 200px;
background-color: #f7f7f7;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, .1);
display: flex;
align-items: center;
justify-content: center;
transition: transform .3s ease-in-out;
}
.active {
transform: scale(1.1); /* 当前激活状态放大 */
}
</style>
```
此代码片段展示了如何使用 Vue.js 和 UniApp 提供的基础组件构建一个具有基本交互性的卡片式轮播图[^1]。注意这里并没有直接依赖于任何特定的第三方库,而是充分利用了框架本身的能力加上一些简单的 CSS 动画效果实现了所需的功能。
阅读全文
相关推荐




















