自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

五分鐘掌握微信小程序輪播圖

企業(yè)動態(tài)
微信小程序輪播圖實(shí)現(xiàn),比Android 輪播圖來說,顯得輕松多了。微信小程序提供swiper組件,官網(wǎng)api提供的swiper滑塊視圖容器。

微信小程序輪播圖實(shí)現(xiàn),比Android 輪播圖來說,顯得輕松多了。

微信小程序提供swiper組件,官網(wǎng)api提供的swiper滑塊視圖容器。

[[216388]]

從公共庫v1.4.0開始,change事件返回detail中包含一個source字段,表示導(dǎo)致變更的原因,可能值如下:

  • autoplay 自動播放導(dǎo)致swiper變化;
  • touch 用戶劃動引起swiper變化;
  • 其他原因?qū)⒂每兆址硎尽?/li>

注意:其中只可放置<swiper-item/>組件,否則會導(dǎo)致未定義的行為。

swiper-item

僅可放置在<swiper/>組件中,寬高自動設(shè)置為100%。

index.wxss

  1. swiper { 
  2.     height: 421.5rpx; 
  3. swiper-item image { 
  4.     width: 100%; 
  5.     height: 100%; 
  6. .swiper-container{ 
  7.   position: relative
  8. .swiper-container .swiper{ 
  9.   height: 300rpx; 
  10. .swiper-container .swiper .img{ 
  11.   width: 100%; 
  12.   height: 100%; 

index.js

  1. Page({ 
  2.   data: { 
  3.     swiperCurrent: 0, 
  4.     indicatorDots: true
  5.     autoplay: true
  6.     interval: 3000, 
  7.     duration: 800, 
  8.     circular:true
  9.     imgUrls: [ 
  10.       'https://p3.pstatp.com/large/43700001e49d85d3ab52'
  11.       'https://p3.pstatp.com/large/39f600038907bf3b9c96'
  12.       'https://p3.pstatp.com/large/31fa0003ed7228adf421' 
  13.     ], 
  14.     links:[ 
  15.       '../user/user'
  16.       '../user/user'
  17.       '../user/user' 
  18.     ] 
  19.      
  20.   }, 
  21.   //輪播圖的切換事件 
  22.   swiperChange: function (e) { 
  23.     this.setData({ 
  24.       swiperCurrent: e.detail.current 
  25.     }) 
  26.   }, 
  27.   //點(diǎn)擊指示點(diǎn)切換 
  28.   chuangEvent: function (e) { 
  29.     this.setData({ 
  30.       swiperCurrent: e.currentTarget.id 
  31.     }) 
  32.   }, 
  33.   //點(diǎn)擊圖片觸發(fā)事件 
  34.   swipclick: function (e) { 
  35.     console.log(this.data.swiperCurrent); 
  36.     wx.switchTab({ 
  37.       url: this.data.links[this.data.swiperCurrent] 
  38.     }) 
  39.   } 
  40. }) 

index.wxml

  1. <view class="swiper-container"
  2.   <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" circular="{{duration}}" current="{{swiperCurrent}}" bindchange="swiperChange" class="swiper"
  3.     <block wx:for="{{imgUrls}}" wx:key="unique"
  4.       <swiper-item> 
  5.         <image src="{{item}}" class="img" bindtap="swipclick" /> 
  6.       </swiper-item> 
  7.     </block> 
  8.   </swiper> 
  9. </view

重要一點(diǎn)是圖片的點(diǎn)擊事件,官網(wǎng)沒明確指出。bindtap="swipclick"

  1. swipclick: function (e) { 
  2.     console.log(this.data.swiperCurrent); 
  3.     wx.switchTab({ 
  4.       url: this.data.links[this.data.swiperCurrent] 
  5.     }) 
  6.   } 

效果圖

【本文為51CTO專欄作者“洪生鵬”的原創(chuàng)稿件,轉(zhuǎn)載請聯(lián)系原作者】

戳這里,看該作者更多好文

責(zé)任編輯:武曉燕 來源: 51CTO專欄
相關(guān)推薦

2021-06-07 09:51:22

原型模式序列化

2009-11-17 14:50:50

Oracle調(diào)優(yōu)

2025-01-24 08:38:47

2019-12-23 16:42:44

JavaScript前端開發(fā)

2009-11-05 10:55:22

Visual Stud

2021-01-11 09:33:37

Maven數(shù)目項(xiàng)目

2017-01-10 09:07:53

tcpdumpGET請求

2023-04-15 20:25:23

微前端

2023-09-29 18:36:57

IDEA編程IDE

2021-01-13 09:23:23

優(yōu)先隊(duì)列React二叉堆

2009-11-16 10:53:30

Oracle Hint

2024-12-11 07:00:00

面向?qū)ο?/a>代碼

2025-03-13 06:22:59

2022-08-04 13:27:35

Pythonopenpyxl

2021-10-20 06:58:10

工具低代碼無代碼

2020-06-16 08:47:53

磁盤

2017-04-25 12:07:51

AndroidWebViewjs

2024-03-21 09:51:22

Python爬蟲瀏覽網(wǎng)站

2024-06-07 08:19:05

2020-12-17 10:00:16

Python協(xié)程線程
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號