本文實例為大家分享了微信小程序實現水平垂直滾動的具體代碼,供大家參考,具體內容如下
要點swiper內部套scroll-view
注意:
1.scroll豎直滾動高度不能給百分比要給px/rpx
2.swiper內部item posiiton定位高度100%
3.swiper高度要給定值
4.如果橫向滾動也要給水平的寬度
代碼
xml
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
|
< swiper class = "tab-box" current = "{{currentTab}}" duration = "300" bindchange = "switchTab" > < swiper-item class = "tab-content" > < scroll-view class = "scroll-height" scroll-y = "true" scroll-with-animation = "{{true}}" > < view class = "cont" > < view class = "jira-card" wx:for = "{{jiraArray}}" wx:for-index = "idx" wx:for-item = "itemJira" wx:key = "idx" > < card itemJira = "{{itemJira}}" data-item = "{{itemJira}}" bindtap = "goDetail" ></ card > </ view > </ view > </ scroll-view > </ swiper-item > < swiper-item class = "tab-content" > < scroll-view class = "scroll-height" scroll-y = "true" scroll-with-animation = "{{true}}" > < view class = "cont" > < view class = "jira-card" wx:for = "{{jiraArray}}" wx:for-index = "idx" wx:for-item = "itemJira" wx:key = "idx" > < card itemJira = "{{itemJira}}" data-item = "{{itemJira}}" bindtap = "goDetail" ></ card > </ view > </ view > </ scroll-view > </ swiper-item > </ swiper > < swiper class = "tab-box" current = "{{currentTab}}" duration = "300" bindchange = "switchTab" > < swiper-item class = "tab-content" > < scroll-view class = "scroll-height" scroll-y = "true" scroll-with-animation = "{{true}}" > < view class = "cont" > < view class = "jira-card" wx:for = "{{jiraArray}}" wx:for-index = "idx" wx:for-item = "itemJira" wx:key = "idx" > < card itemJira = "{{itemJira}}" data-item = "{{itemJira}}" bindtap = "goDetail" ></ card > </ view > </ view > </ scroll-view > </ swiper-item > < swiper-item class = "tab-content" > < scroll-view class = "scroll-height" scroll-y = "true" scroll-with-animation = "{{true}}" > < view class = "cont" > < view class = "jira-card" wx:for = "{{jiraArray}}" wx:for-index = "idx" wx:for-item = "itemJira" wx:key = "idx" > < card itemJira = "{{itemJira}}" data-item = "{{itemJira}}" bindtap = "goDetail" ></ card > </ view > </ view > </ scroll-view > </ swiper-item > </ swiper > |
wxss
1
2
3
4
5
6
|
.tab-box{ height : 1040 rpx; } .scroll-height { height : 1040 rpx; } |
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
myAudit(){ this .setData({ currentTab:0, }) }, myInitiate(){ this .setData({ currentTab:1, // jiraArray:[] }) }, switchTab(event){ var cur = event.detail.current; var singleNavWidth = this .data.windowWidth / 5; this .setData({ currentTab: cur, navScrollLeft: (cur - 2) * singleNavWidth }); } |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/s2422617864/article/details/114834271