自定义小程序swiper指示点样式

image

小程序不提供swiper指示点的样式自定义。只能自己写一个指示点样式,替换掉。

index.wxml


<view class='warp'>

  <swiper class='swiper' current='{{currentSwiper}}' autoplay bindchange='swiperChange'>

    <block wx:for="{{imgUrls}}" wx:key="">

      <swiper-item>

        <image src='{{item}}' class='img'></image>

      </swiper-item>

    </block>

  </swiper>

  <view class='dots'>

    <block wx:for="{{imgUrls}}" wx:key="">

      <view class='dot {{index == currentSwiper ?"active":""}}'></view>

    </block>

  </view>

</view>

index.wxss


.warp{

  height: auto;

  position: relative;

}

.swiper{

  height: 220rpx;

}

.swiper .img{

  width: 100%;

  height: 100%;

}

.dots{

  width: 256rpx;

  height: 36rpx;

  display: flex; 

  flex-direction: row;

  position: absolute;

  right: 20rpx;

  bottom: 5rpx;

  justify-content: center;

  align-items: center;

}

.dot{

width: 30rpx;

height: 8rpx;

border-radius: 30rpx;

margin-right: 10rpx;

background-color: white;

}

.active{

  width: 70rpx;

  background-color: coral;

}

index.js


Page({

  data: {

    imgUrls: [

      'http://47.105.139.205/1.jpg',

      'http://47.105.139.205/2.jpg',

      'http://47.105.139.205/3.jpg'

    ],

    currentSwiper : 0 

  },

  swiperChange:function(event){     

    this.setData({

      currentSwiper: event.detail.current

    });

  },

})

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容