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

2022-08-15  本文已影响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;
                }
上一篇 下一篇

猜你喜欢

热点阅读