美文网首页
小程序——动态控制最小高度

小程序——动态控制最小高度

作者: 我是Alex | 来源:发表于2020-04-26 12:58 被阅读0次
    <!-- index.wxml -->
    <view class="container" style="min-height: {{minHeight}}rpx;">
      ·
      ·
      ·
    </view>
    
    <!-- index.js -->
    data: {
        minHeight:getApp().globalData.minHeight
      },
    
    <!-- app.js -->
    App({
      onLaunch: function () {
            let that = this;
            // 获取最小高度
            that.getMinHeight();
            
      },
        // 获取最小高度
        getMinHeight(){
            let that = this;
            wx.getSystemInfo({
                success: function(res) {
                    let windowHeightRpx = (res.windowHeight * (750 / res.windowWidth)); //将高度乘以换算后的该设备的rpx与px的比例
                    that.globalData.minHeight = windowHeightRpx - 158;
                }
            })
        },
      globalData: {
            hasLogin:false,
            minHeight:0
      }
    })
    

    相关文章

      网友评论

          本文标题:小程序——动态控制最小高度

          本文链接:https://www.haomeiwen.com/subject/swpdwhtx.html