小程序轮播图 swiper当前滑块容器样式

请添加图片描述
官网截图 主要是这两个参数配置 可以让当前滑块露出前一项和后一项的一部分

轮播部分
<swiper style="height:260rpx" class="swiper" previous-margin='30' next-margin='30' @change="swiperChange" :circular="true" :indicator-dots="true" :autoplay="true" :interval="6000" :duration="500">
            <block v-for="(item, index) in swiperList" :key="index">
                <swiper-item>
                    <div class="swiper-item" :class="currentIndex == index ? '': 'not-active'">
                        <div style="margin-top: 30rpx;">
                            <p class="num">{{item.total}}</p>
                            <p class="words">{{item.type}}</p>
                        </div>
                        <div style="margin-top: 30rpx;">
                            <p class="num">{{item.normal}}</p>
                            <p class="words">当月正常使用</p>
                        </div>
                        <div style="margin-top: 16rpx;">
                            <p class="percent">{{item.rate}}</p>
                            <p class="progress"><span :style="'width:'+item.rate"></span></p>
                            <p class="rate">溯源平台使用率</p>
                        </div>
                    </div>
                </swiper-item>
            </block>
        </swiper>

data中定义 currentIndex:‘0’

    // 轮播
    swiperChange(e){
        this.currentIndex = e.mp.detail.current
    }
//非当前滑块的样式
.not-active{
    scale: 0.9;
}
// 指示点样式
.swiper /deep/ .wx-swiper-dot{
  width: 10rpx;
  height: 10rpx;
  border-radius: 10rpx;
  border: 1px solid rgba(124, 165, 255, 1);
  }

效果展示
在这里插入图片描述

微信小程序中的 Swiper 组件是一个用于创建轮播图或者滑动列表的常用模块,它允许你轻松地实现滚动效果。要在小程序中使用 Swiper,你需要按照以下步骤操作: 1. 导入 Swiper 组件:在需要使用 Swiper 的页面的 WXML 文件中,通过 `import` 或者 `<import>` 标签导入组件库,如: ```html <import src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js" /> <view> <wxs:import name="swiper" src="/path/to/your/components/swiper.swiper.wxml" /> <!-- 使用自定义组件路径 --> </view> ``` 2. 定义 Swiper 组件:在 WXML 中,你可以创建一个新的 Swiper 组件并配置其属性,例如显示多少张图片、切换速度等。示例如下: ```html <swiper indicator-dots="{{showDots}}" interval="{{intervalTime}}" autoplay="{{autoplay}}"> <block wx:for="{{items}}"> <swiper-item> <image src="{{item.src}}" style="width: 100%; height: 100%" /> </swiper-item> </block> </swiper> ``` 其中,`items` 是包含所有滑动内容的数组,`indicator-dots` 控制是否显示指示点,`interval-time` 设置切换时间间隔,`autoplay` 是否自动播放。 3. 配置 JavaScript 脚本:在对应的 JS 文件中,设置 Swiper 的数据以及事件处理。例如,初始化 Swiper 和控制滑动的行为: ```javascript Page({ data: { items: [ {src: 'image1.jpg'}, {src: 'image2.jpg'}, {src: 'image3.jpg'} ], showDots: true, intervalTime: 2000, autoplay: true }, onLoad() { this.createSwiper(); }, createSwiper() { wx.createSelectorQuery().select('#swiper').boundingClientRect((rect) => { this.setData({ swiperOption: { width: rect.width, height: rect.height, indicators: this.data.showDots ? ['dot'] : [], autoplay: this.data.autoplay, interval: this.data.intervalTime } }); let mySwiper = new wx.Swiper({ ...this.data.swiperOption, indicatorDots: this.data.showDots, // 更多选项... }); }); } }) ``` 4. CSS 样式调整:如果需要,你还可以添加一些 CSS 样式来自定义 Swiper样式,比如改变滑块的大小、位置等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值