ホームページ > WeChat アプレット > ミニプログラム開発 > WeChat ミニ プログラム テンプレート ページング スライド バー

WeChat ミニ プログラム テンプレート ページング スライド バー

高洛峰
リリース: 2017-02-18 12:59:06
オリジナル
2356 人が閲覧しました

この記事の例では、参考のために WeChat アプレット ページング スライド バーの特定のコードを共有します。具体的な内容は次のとおりです。

1. ページング バーはスライド ビューにバインドされます2.ページング バーを対応するビューに自動的にスライドします

3. ビューに対応するページング バーにスワイプして、選択したスタイルを自動的に表示します




レンダリング


コードをアップロードします WeChat ミニ プログラム テンプレート ページング スライド バー

wxml

1

2

3

4

5

6

7

8

9

10

11

12

<view class="tapNav">

 <view class="{{tabArr.tabCurrentIndex==0?&#39;active&#39;:&#39;&#39;}}" data-index="0" bindtap="veHandle">分页标签1</view>

 <view class="{{tabArr.tabCurrentIndex==1?&#39;active&#39;:&#39;&#39;}}" data-index="1" bindtap="veHandle">分页标签2</view>

 <view class="{{tabArr.tabCurrentIndex==2?&#39;active&#39;:&#39;&#39;}}" data-index="2" bindtap="veHandle">分页标签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>

ログイン後にコピー

wxss

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

/*

1.横向排列分页标签

2.每个分页标签各占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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

//index.js

//获取应用实例

var app = getApp()

Page({

 data: {

 // 图片地址

 imgUrls: [

  &#39;http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg&#39;,

  &#39;http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg&#39;,

  &#39;http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg&#39;

 ],

 //是否显示面板指示点

 indicatorDots: true,

 //自动播放

 autoplay: true,

 //切换时间间隔

 interval: 2000,

 //滑动时长

 duration: 1000,

 //存放滑动视图的current

 current:0,

 //分页标签class条件判断的值

 tabArr:{

  tabCurrentIndex:0

 }

 },

 //事件处理函数

 //触摸分页标签触发事件

 veHandle:function(e){

 //每个分页标签都设置了data-index,触摸触发事件获取此数值

 //用此数值替换滑动视图的current

 //用此数值替换分页标签class判断的值

 console.log(e.target.dataset.index)

 var currentIndex = e.target.dataset.index

 this.setData({

  current:currentIndex,

  "tabArr.tabCurrentIndex":currentIndex

 })

 },

 //通过滑块视图的current改变触发事件

 swiperChange:function(e){

 //获取视图滑块当前的current

 //用此数值替换分页标签的current的值

 console.log(e.detail.current)

 var swiperCurrent = e.detail.current;

 this.setData({

  &#39;tabArr.tabCurrentIndex&#39;:swiperCurrent

 })

 },

 onLoad: function () {

 console.log(&#39;onLoad&#39;)

 }

})

ログイン後にコピー

以上が、皆さんの学習に役立つことを願っています。 PHP 中国語 Web サイトをサポートします。

WeChat アプレット テンプレートのページング スライド バーに関連するその他の記事については、PHP 中国語 Web サイトに注目してください。

このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート