微信小程序==>定義輪播圖swiper dots默認樣式

html

<view class="swiper-container">
  <swiper autoplay="auto" interval="5000" duration="500" current="{{swiperCurrent}}" bindchange="swiperChange" class="swiper">
    <block wx:for="{{imgUrl}}" wx:key="unique">
      <swiper-item>
        <image src="{{item}}" class="img"></image>
      </swiper-item>
    </block>
  </swiper>
 
  <view class="dots">
    <block wx:for="{{imgUrl}}" wx:key="unique">
      <view class="dot{{index == swiperCurrent ? ' active' : ''}}"></view>
    </block>
  </view>
</view>

wxss

.swiper-container{
  position: relative;
}
.swiper-container .swiper{
  height: 300rpx;
}
.swiper-container .swiper .img{
  width: 100%;
  height: 100%;
}
.swiper-container .dots{
  position: absolute;
  left: 0;
  right: 0;
  bottom: 20rpx;
  display: flex;
  justify-content: center;
}
.swiper-container .dots .dot{
  margin: 0 8rpx;
  width: 14rpx;
  height: 14rpx;
  background: #fff;
  border-radius: 8rpx;
  transition: all .6s;
}
.swiper-container .dots .dotactive{
  width: 24rpx;
  background: #f80;
}

js


data: {
imgUrl: [
  // 里面寫圖片地址
 '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'
],
swiperCurrent: 0,
},

swiperChange:function(e){

this.setData({

swiperCurrent: e.detail.current  // current 改變時會觸發(fā) change 事件

    })
}
修改成功.png

wx:key
如果列表中項目的位置會動態(tài)改變或者有新的項目添加到列表中,并且希望列表中的項目保持自己的特征和狀態(tài)(如 <input/> 中的輸入內(nèi)容,<switch/> 的選中狀態(tài)),需要使用 wx:key 來指定列表中項目的唯一的標識符。

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • WXML WXML(WeiXin Markup Language)是微信的一套標簽語言,結(jié)合基礎組件、事件系統(tǒng),可...
    許劍鋒閱讀 7,284評論 3 51
  • 最近做了一個投票的微信小程序,開發(fā)過程主要還是參考官方文檔:https://mp.weixin.qq.com/de...
    june5253閱讀 22,208評論 1 11
  • 最近小程序被炒的火熱。很多人應該已經(jīng)嘗試了微信小程序,我也抱著學習的態(tài)度,準備研究一下。研究之后感覺還可以,如果有...
    范小飯_閱讀 3,254評論 0 13
  • 微信小程序在無論在功能、文檔及相關支持方面,都是優(yōu)于前面幾種微信賬號類型,它提供了很多原生程序才有的接口,使得我們...
    未央大佬閱讀 2,397評論 0 12
  • 窗外 飛翔的翅膀 在藍天下 去任何你想去的地方 那有森林 有草原 有水塘 但也有獵槍,有天敵。
    舟舟style閱讀 188評論 0 0

友情鏈接更多精彩內(nèi)容