温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

微信小程序如何解决自定义弹窗滚动与页面滚动冲突的问题

发布时间:2021-06-30 16:05:09 阅读:137 作者:小新 栏目:web开发
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

这篇文章主要介绍微信小程序如何解决自定义弹窗滚动与页面滚动冲突的问题,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

具体内容如下

先看效果是否是自己需要的

微信小程序如何解决自定义弹窗滚动与页面滚动冲突的问题

实现步骤:

1.整个布局用作为根节点包裹所有view,并动态绑定scroll-view的scroll-y属性
2.样式文件中设置Page的overflow-y属性值为hidden
3.样式文件中设置scroll-view的height属性值为100%
4.打开自定义弹窗的点击事件中,更改isScroll的值为false,关闭弹窗的点击事件中,更改isScroll的值为true

JS:

Page({
 /**
  * 页面的初始数据
  */
 data: {
  arrayDatanull,
  dialogDatanull,
  isDialogShowfalse,
  isScrolltrue
 },
 /**
  * 生命周期函数--监听页面加载
  */
 onLoad: function (options) {
  //构建测试数据
  let data = new Array();
  let dialog = new Array();
  for (let i = 0; i < 25; i++) {
   data[i] = '我是测试-----------' + i;
   dialog[i] = {
    name'我是弹窗-' + i,
    isSelectedfalse
   };
  }
  this.setData({
   arrayData: data,
   dialogData: dialog
  });
 },
 /**
  * 显示、关闭弹窗
  */
 showDialog: function (e) {
  var currentStatu = e.currentTarget.dataset.statu;
  console.log('currentStatu:', currentStatu);
  //关闭 
  if (currentStatu == "close") {
   this.setData({
    isDialogShowfalse,
    isScrolltrue
   });
  }
  // 显示 
  if (currentStatu == "open") {
   this.setData({
    isDialogShowtrue,
    isScrollfalse
   });
  }
 }
})

wxml:

<button>做点什么</button>
<scroll-view scroll-y="{{isScroll}}"> 
 <view class="rootView">
  <view class="inTable">
   <view wx:for="{{arrayData}}" wx:key="" class="unitItemLeft" bindtap="showDialog" data-statu="open">
    <input class="baseItemWithBorder" value="{{item}}" disabled />
   </view>
  </view>
 </view>
</scroll-view>


<!--测试弹窗--> 
<view class="dialogMarsk" bindtap="showDialog" data-statu="close" wx:if="{{isDialogShow}}"></view> 
 <!--dialog-->
<view class="dialog" wx:if="{{isDialogShow}}">
 <view class="appreciationTitle">
  <text >我是弹窗</text>
 </view>
 <view wx:for="{{dialogData}}" class="appreciationTable">
  <view class="unitItemLeft">
   <text class="baseItemWithBorder">{{item.name}}</text>
  </view>
 </view>
</view>

wxss:

Page {
 position: absolute;
 font-size36rpx;
 width100%;
 height100%;
 display: block;
 background#FAFAFA;
 overflow-y: hidden;
}
 scroll-view {
 height100%;
} 
.rootView{
 /* width: 100%; */
 padding10rpx;
 display: flex;
 flex-direction: column;
}
.baseItemWithBorder{
 flex-grow1;
 height100%;
 padding-left20rpx;
 padding-right20rpx;
 border-bottom: solid 1rpx gainsboro;
}
.inTable{
 width100%;
 display: flex;
 box-shadow:5px 5px 10px gray;
 flex-direction: column;
 margin-top40rpx;
 background: white;
}
.inDetail{
 width100%;
 height80rpx;
 display: flex;
}
.unitLeft{
 justify-content: flex-start;
 padding-left20rpx;
}
.unitItemLeft{
 width100%;
 height80rpx;
 display: flex;
 flex-direction: row;
}
.dialogMarsk { 
 width100%; 
 height100%; 
 position: fixed; 
 top0; 
 left0; 
 z-index1000; 
 backgroundrgba(0000.6);
 overflow: hidden; 
}
.dialog {
 width80%;
 height50%; 
 position: fixed; 
 top10%;
 z-index1001; 
 background#FAFAFA;
 border-radius3px;
 overflow-y: scroll;
}
.appreciationTable{
 width98%;
 display: flex;
 flex-direction: column;
 background: white;
 margin0 10rpx;
}
.appreciationTitle{
 width100%;
 display: flex;
 flex-direction: column;
 align-items: center;
 justify-content: center;
 margin-top20rpx;
 margin-bottom20rpx;
}

以上是“微信小程序如何解决自定义弹窗滚动与页面滚动冲突的问题”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×