代码写的比较简单,能用就行,希望对大家有帮助
也可以去swiper官网用他们的组件,地址Swiper中文网-轮播图幻灯片js插件,H5页面前端开发
值得注意的是中间图片放大的时候<swiper-item>会有一个默认的 overflow: hidden;会把中间内容的遮去一部分,改为默认的就行
uni-swiper-item {
overflow: inherit;//改为默认的就行
}
见代码
HTML
<view class="heade">
<swiper class="swiper" display-multiple-items='5' circular='true' previous-margin='-50rpx'
next-margin='-90rpx' current='0' @change="swiperChange" indicator-active-color='red'>
<block v-for="(item,index) in 6" :key='index'>
<swiper-item class="sitem">
<view class="swiper-item" :class="{current:index==currentIndex}">
{{index}}
</view>
</swiper-item>
</block>
</swiper>
</view>
JS
export default {
data() {
return {
currentIndex: 2
}
},
methods: {
swiperChange(event) {
console.log(event.detail)
let a = 2;
if (event.detail.current > 3) {
a = -4
}
this.currentIndex = event.detail.current + a
}
}
}
CSS
.heade {
width: 100vw;
height: 756rpx;
//background: url(../../static/images/active_pag/heade_axnc@2x.png) no-repeat;
//background-size: 100%;
position: relative;
}
.sitem {
box-sizing: border-box;
padding-top: 25rpx;
}
.swiper {
width: 100vw;
position: absolute;
bottom: 0;
left: 0;
}
.current {
transform: scale(1.2);
position: absolute;
background: red !important;
top: -6rpx;
left: 0rpx;
z-index: 10;
border-radius: 8rpx;
transition: all 0.2s ease-in 0s;
}
uni-swiper-item {
overflow: inherit;//改为默认的就行
}
.swiper-item {
width: 148rpx;
height: 172rpx;
background: #fff;
border-radius: 8rpx;
position: relative;
}