国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

微信小程序模板之分頁滑動欄

2019-11-19 17:39:25
字體:
供稿:網(wǎng)友

本文實(shí)例為大家分享了微信小程序分頁滑動欄的具體代碼,供大家參考,具體內(nèi)容如下

功能:

1.分頁欄與滑動視圖綁定
2.點(diǎn)擊分頁欄自動滑動到對應(yīng)視圖
3.滑動的到視圖對應(yīng)分頁欄自動顯示選中樣式

效果圖

上代碼

wxml

<view class="tapNav"> <view class="{{tabArr.tabCurrentIndex==0?'active':''}}" data-index="0" bindtap="veHandle">分頁標(biāo)簽1</view> <view class="{{tabArr.tabCurrentIndex==1?'active':''}}" data-index="1" bindtap="veHandle">分頁標(biāo)簽2</view> <view class="{{tabArr.tabCurrentIndex==2?'active':''}}" data-index="2" bindtap="veHandle">分頁標(biāo)簽3</view></view><swiper id="swiper" indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}" current="{{current}}" bindchange="swiperChange"> <block wx:for="{{imgUrls}}"> <swiper-item id="swiper-item">  <image id="imgae" src="{{item}}" class="slide-image" width="355" height="150"/> </swiper-item> </block>

</swiper>

wxss

/*1.橫向排列分頁標(biāo)簽2.每個分頁標(biāo)簽各占1/3*/.tapNav { display: flex; flex-direction: row;}.tapNav view{ flex:1; width:200rpx; height:100rpx; text-align: center; line-height: 100rpx; font-family: "微軟雅黑";}/*選中樣式*/.tapNav .active { color:blue; border-bottom:4rpx solid mediumseagreen;}#swiper { margin-top:40rpx;}#swiper image{ width:100%;}

js

//index.js//獲取應(yīng)用實(shí)例var app = getApp()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' ], //是否顯示面板指示點(diǎn) indicatorDots: true, //自動播放 autoplay: true, //切換時間間隔 interval: 2000, //滑動時長 duration: 1000, //存放滑動視圖的current current:0, //分頁標(biāo)簽class條件判斷的值 tabArr:{  tabCurrentIndex:0 } }, //事件處理函數(shù) //觸摸分頁標(biāo)簽觸發(fā)事件 veHandle:function(e){ //每個分頁標(biāo)簽都設(shè)置了data-index,觸摸觸發(fā)事件獲取此數(shù)值 //用此數(shù)值替換滑動視圖的current //用此數(shù)值替換分頁標(biāo)簽class判斷的值 console.log(e.target.dataset.index) var currentIndex = e.target.dataset.index this.setData({  current:currentIndex,  "tabArr.tabCurrentIndex":currentIndex }) }, //通過滑塊視圖的current改變觸發(fā)事件 swiperChange:function(e){ //獲取視圖滑塊當(dāng)前的current //用此數(shù)值替換分頁標(biāo)簽的current的值 console.log(e.detail.current) var swiperCurrent = e.detail.current; this.setData({  'tabArr.tabCurrentIndex':swiperCurrent }) }, onLoad: function () { console.log('onLoad') }})

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 甘肃省| 通山县| 开阳县| 云梦县| 克山县| 兰溪市| 西藏| 汝阳县| 莱州市| 卫辉市| 武平县| 定安县| 固镇县| 乐山市| 六枝特区| 文登市| 全椒县| 运城市| 邳州市| 卫辉市| 民和| 包头市| 赣榆县| 杭锦后旗| 焦作市| 原阳县| 横峰县| 高陵县| 定州市| 新巴尔虎右旗| 龙井市| 辽阳县| 容城县| 和平区| 沙田区| 武陟县| 新泰市| 息烽县| 苍溪县| 措勤县| 德钦县|