微信小程序修改swiper默认指示器样式

导读:本篇文章讲解 微信小程序修改swiper默认指示器样式,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

修改官方swiper样式

从微信官方微信开发文档中心复制swiper 代码块。傻瓜式教程

wxml定义

<view class="wrap">
    <swiper class="swipers" autoplay="{{autoplay}}" current="{{currentSwiper}}" bindchange="swiperChange">  
        <block wx:for="{{imgUrls}}">  
            <swiper-item>  
                 <image src="{{item}}" class="slide-image" width="100%" height="150" ></image>  
            </swiper-item>  
        </block>  
    </swiper>  
   <!--重置小圆点的样式  -->
    <view class="dots">  
        <block wx:for="{{imgUrls}}">  
            <view class="dot{{index == currentSwiper ? ' active' : ''}}"></view>  
        </block>  
    </view>  
</view>


wxss定义样式
.wrap {
  height: auto;
  position: relative;
  width: 100%;
}

.swipers {
  height: 350rpx;
  width: 100%;
}

.slide-image {
  display: block;
  width: 100%;
  height: 100%;
}

/*用来包裹所有的小圆点  */

.dots {
  width: 156rpx;
  height: 36rpx;
  display: flex;
  flex-direction: row;
  position: absolute;
  left: 320rpx;
  bottom: 20rpx;
}

/*未选中时的小圆点样式 */

.dot {
  width: 26rpx;
  height: 26rpx;
  border-radius: 50%;
  margin-right: 26rpx;
  background-color: white;
}

/*选中以后的小圆点样式  */

.active {
  width: 26rpx;
  height: 26rpx;
  background-color: coral;
}
赋值

Page({
  data: {
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    currentSwiper: 0,
    autoplay: true
  },
  swiperChange: function (e) {
    this.setData({
      currentSwiper: e.detail.current
    })
  }
})  

效果图:

这里写图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/12847.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!