1.获取屏幕宽度,并赋值给view

<view class=”ships-img” style=”height:{{windowWidth}}px;”></view>

  1. wx.getSystemInfo({
  2. success: function (res) {
  3. // console.log(res.windowWidth) 屏幕宽度
  4. that.setData({
  5. windowWidth: res.windowWidth
  6. })
  7. }
  8. })

 

2.最近遇到自定义弹窗滚动问题,当文本页面过长,同时自定义弹窗也过长,即两者都需要滚动的时候,想要自定义弹窗滚动却触发的是页面的滚动。

解决思路:在打开弹窗的时候,让页面不可滚动;关闭弹窗后,恢复页面滚动。

  1. <scroll-view scroll-y="{{isScroll}}">
  2. <view class="rootView">
  3. <view wx:for="{{arrayData}}" wx:key="" bindtap="showDialog" data-statu="open" class="inBoxVIew">
  4. <text>{{item}}</text>
  5. </view>
  6. <!--测试弹窗-->
  7. <view class="dialogbox" bindtap="showDialog" data-statu="close" wx:if="{{isDialogShow}}"></view>
  8. <!--dialog-->
  9. <view class="dialog" wx:if="{{isDialogShow}}">
  10. <view class="windowTitle">
  11. <text style="font-size:24px;">我是弹窗</text>
  12. </view>
  13. <view wx:for="{{dialogData}}" class="windowTable">
  14. <text>{{item.name}}</text>
  15. </view>
  16. </view>
  17. </view>
  18. </scroll-view>
  1. Page {
  2. position: absolute;
  3. font-size: 36rpx;
  4. width: 100%;
  5. height: 100%;
  6. display: block;
  7. background: #fff;
  8. }
  9. scroll-view {
  10. height: 100%;
  11. }
  12. .rootView{
  13. padding: 10rpx;
  14. }
  15. .inBoxVIew{
  16. padding:20rpx 0;
  17. text-align: center;
  18. }
  19. .dialogbox {
  20. width: 100%;
  21. height: 100%;
  22. position: fixed;
  23. top: 0;
  24. left: 0;
  25. z-index: 1000;
  26. background: rgba(0, 0, 0, 0.6);
  27. overflow: hidden;
  28. }
  29. .dialog {
  30. width: 80%;
  31. height: 50%;
  32. position: fixed;
  33. top:50%;
  34. left:50%;
  35. margin-top:-25%;
  36. margin-left:-40%;
  37. z-index: 1001;
  38. background: #FAFAFA;
  39. border-radius: 3px;
  40. overflow-y: scroll;
  41. }
  42. .windowTable{
  43. width: 98%;
  44. background: white;
  45. margin: 0 10rpx;
  46. padding:10rpx 0;
  47. }
  48. .windowTitle{
  49. width: 100%;
  50. text-align: center;
  51. }
  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. arrayData: null,
  7. dialogData: null,
  8. isDialogShow: false,
  9. isScroll: true
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (options) {
  15. //构建测试数据
  16. let data = new Array();
  17. let dialog = new Array();
  18. for (let i = 0; i < 25; i++) {
  19. data[i] = \'点击我,测试\' + i;
  20. dialog[i] = {
  21. name: \'我是弹窗-\' + i,
  22. isSelected: false
  23. };
  24. }
  25. this.setData({
  26. arrayData: data,
  27. dialogData: dialog
  28. });
  29. },
  30. /**
  31. * 显示、关闭弹窗
  32. */
  33. showDialog: function (e) {
  34. var currentStatu = e.currentTarget.dataset.statu;
  35. console.log(\'currentStatu:\', currentStatu);
  36. //关闭
  37. if (currentStatu == "close") {
  38. this.setData({
  39. isDialogShow: false,
  40. isScroll: true
  41. });
  42. }
  43. // 显示
  44. if (currentStatu == "open") {
  45. this.setData({
  46. isDialogShow: true,
  47. isScroll: false
  48. });
  49. }
  50. },
  51. })

 

 

 

 

 

版权声明:本文为juewuzhe原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/juewuzhe/p/7942241.html