美文网首页
uniapp获取屏幕高度和组件高度

uniapp获取屏幕高度和组件高度

作者: 冰点雨 | 来源:发表于2022-08-15 11:52 被阅读0次

获取组件高度

let view = uni.createSelectorQuery().select(".home-data");
            view.boundingClientRect(data=>{
                // this.clientHeight =  data.height;
                this.clientHeight = 4000;
            }).exec();

获取屏幕高度

        uni.getSystemInfo({
                success:(res)=>{
                    this.clientHeight = res.windowHeight - this.getClientHeight();
                }
            });

// 获取可视区域高度[兼容]
            getClientHeight(){
                const res = uni.getSystemInfoSync();
                const system = res.platform;
                if(system === 'ios'){
                    return 44+res.statusBarHeight;
                }else if(system === 'android'){
                    return 48+res.statusBarHeight;
                }else{
                    return 0;
                }

相关文章

网友评论

      本文标题:uniapp获取屏幕高度和组件高度

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