您好,登錄后才能下訂單哦!
怎么在微信小程序中實現一個水平垂直滾動功能?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
具體內容如下
要點swiper內部套scroll-view
注意:
1.scroll豎直滾動高度不能給百分比要給px/rpx
2.swiper內部item posiiton定位高度100%
3.swiper高度要給定值
4.如果橫向滾動也要給水平的寬度
代碼
xml
<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
.tab-box{ height: 1040rpx; } .scroll-height { height: 1040rpx; }
js
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 }); }
關于怎么在微信小程序中實現一個水平垂直滾動功能問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。