【微信小程序】swiper自定义样式:指示点样式 wx-swiper-dot

前言

  • 调试基础库:2.26.0
    在这里插入图片描述

swiper

    <view class="swiper">
      <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
        <block wx:for="{{background}}" wx:key="*this">
          <swiper-item>
            <view class="swiper-item {{item}}"></view>
          </swiper-item>
        </block>
      </swiper>
    </view>

swiper 样式

  • .wx-swiper-dots : 指示点容器样式
  • .wx-swiper-dots-horizontal : 水平滑动的指示点容器样式,其在.wx-swiper-dots内。
  • .wx-swiper-dot :指示点样式
  • .wx-swiper-dot-active : 当前指示点样式

指示点颜色

默认指示点颜色
在这里插入图片描述
改变指示点颜色

.swiper .wx-swiper-dot {
  background-color: rgba(255,255,255,0.7);
}
.swiper .wx-swiper-dot-active {
  background-color:#ff4e5b;
}

在这里插入图片描述

指示点形状

默认指示点形状
在这里插入图片描述
改变指示点形状

.swiper .wx-swiper-dots-horizontal .wx-swiper-dot {
  width: 45rpx;
  height: 8rpx;
  border-radius: 5rpx;
}

在这里插入图片描述

指示点位置

默认指示点位置贴近底部
在这里插入图片描述
改变指示点位置

.swiper .wx-swiper-dots.wx-swiper-dots-horizontal {
  position: absolute;
  bottom: 40rpx;
}
  • .wx-swiper-dots.wx-swiper-dots-horizontal,注意中间,没有空格
    在这里插入图片描述
    或者
.swiper .wx-swiper-dots.wx-swiper-dots-horizontal {
  margin-bottom: 40rpx;
}
  • .wx-swiper-dots.wx-swiper-dots-horizontal,注意中间,没有空格

参考

https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html
https://blog.csdn.net/qq_39399966/article/details/113342668
https://blog.csdn.net/IT_iosers/article/details/123922736
https://wangjiabin.blog.csdn.net/article/details/108194235
https://blog.csdn.net/weixin_42063951/article/details/111059699

微信小程序中,`swiper`组件的指示样式默认是显示在滑块上的。如果需要在弹窗上显示指示器,可以通过自定义指示器来实现。具体步骤如下: 1. **隐藏默认指示器**:通过设置`indicator-dots`为`false`来隐藏默认指示器。 2. **自定义指示器**:在`swiper`组件外部添加自定义指示器元素,并通过`wx:for`循环和`wx:key`来动态生成指示器。 3. **绑定事件**:通过`bindchange`事件来更新当前页面的索引,从而控制指示器的样式。 以下是一个示例代码: ```xml <!-- wxml --> <view class="container"> <swiper indicator-dots="{{false}}" bindchange="onSwiperChange" autoplay="{{false}}" current="{{current}}" style="height: 200px;"> <block wx:for="{{images}}" wx:key="index"> <swiper-item> <image src="{{item}}" mode="aspectFill" style="width: 100%; height: 100%;" /> </swiper-item> </block> </swiper> <view class="indicator"> <view wx:for="{{images}}" wx:key="index" class="dot {{index === current ? 'active' : ''}}"></view> </view> </view> ``` ```css /* wxss */ .container { position: relative; } .indicator { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); display: flex; } .dot { width: 10px; height: 10px; margin: 0 5px; background-color: rgba(255, 255, 255, 0.5); border-radius: 50%; } .dot.active { background-color: rgba(255, 255, 255, 1); } ``` ```javascript // js Page({ data: { images: [ 'https://example.com/image1.jpg', 'https://example.com/image2.jpg', 'https://example.com/image3.jpg' ], current: 0 }, onSwiperChange(e) { this.setData({ current: e.detail.current }); } }); ``` 在这个示例中,`swiper`组件的指示器被隐藏了,通过自定义的`dot`元素来显示指示器,并通过`current`变量来控制当前页面的指示样式
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值