微信小程序将view动态填满全屏

一、在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的高度为可用窗口高度。

转载于:https://www.cnblogs.com/Man-Dream-Necessary/p/9392340.html

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值