溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

微信小程序修改swiper默認指示器樣式的實例代碼

發(fā)布時間:2020-10-08 16:42:13 來源:腳本之家 閱讀:237 作者:還有星星 欄目:web開發(fā)

修改官方swiper樣式

從微信官方微信開發(fā)文檔中心復制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
 })
 }
}) 

效果圖:

微信小程序修改swiper默認指示器樣式的實例代碼

總結

以上所述是小編給大家介紹的微信小程序修改swiper默認指示器樣式的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網(wǎng)站的支持!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI