一、在app.js利用官方方法获取设备信息,将获取到的screenHeight、windowHeight度量单位统一由rpx换算为px

注:官方文档给出 【rpx换算px (屏幕宽度/750)  】【 px换算rpx (750/屏幕宽度)】

App({
    onLaunch: function() {
        wx.getSystemInfo({
            success: res => {
                this.globalData.systemInfo = res
this.globalData.windowHeight = res.windowHeight /(res.windowWidth /750)
this.globalData.screenHeight = res.screenHeight /(res.screenWidth /750)
} }) }, globalData: { systemInfo: null,
windowHeight: null, // rpx换算px后的窗口高度
screenHeight: null, // rpx换算px后的屏幕高度
} })

二、在要使用的页面的js文件里引用
const app = getApp()
Page({
    data: {
        windowHeight: 0,
        screenHeight: 0
    },
    onLoad: function() {
        this.setData({
            windowHeight: app.globalData.windowHeight,
            screenHeight: app.globalData.screenHeight
        })
    }
})

三、在要使用的页面的wxml里使用,若有底部导航栏tabBar则使用windowHeight,若没有则使用screenHeight

<view class='contentListBox' style='height:{{windowHeight}}rpx'>
    <view wx:key='index' wx:for='{{contentList}}' wx:for-index="index" wx:for-item="item">
        {{item}}
    </view>
</view>

此时class为contentListBox的view的高度为可用窗口高度。

相关文章:

  • 2022-01-21
  • 2022-12-23
  • 2021-10-01
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2021-12-09
  • 2022-01-07
  • 2021-09-12
  • 2021-06-25
  • 2021-04-18
相关资源
相似解决方案