欢迎来到代码驿站!

JavaScript代码

当前位置:首页 > 网页前端 > JavaScript代码

微信小程序实现水平垂直滚动

时间:2021-09-13 08:01:20|栏目:JavaScript代码|点击:

本文实例为大家分享了微信小程序实现水平垂直滚动的具体代码,供大家参考,具体内容如下

要点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
 });
}

上一篇:微信小程序中的店铺评分组件及vue中用svg实现的评分显示组件

栏    目:JavaScript代码

下一篇:JS将制定内容复制到剪切板示例代码

本文标题:微信小程序实现水平垂直滚动

本文地址:http://www.codeinn.net/misctech/174677.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有