uni-app中获取设备屏幕宽高
官方文档uni.getSystemInfo
uni.getSystemInfo是异步获取
1 2 3 4 5 6 7 8 9 10 11
| uni.getSystemInfo({ success: function (res) { console.log(res.model); console.log(res.pixelRatio); console.log(res.windowWidth); console.log(res.windowHeight); console.log(res.language); console.log(res.version); console.log(res.platform); } });
|
uni.getSystemInfoSync() 是同步获取
1 2 3 4 5 6 7 8 9 10 11 12
| try { const res = uni.getSystemInfoSync(); console.log(res.model); console.log(res.pixelRatio); console.log(res.windowWidth); //设备宽度 console.log(res.windowHeight); //设备高度 console.log(res.language); console.log(res.version); console.log(res.platform); } catch (e) { // error }
|
uni-app获取元素高度
1 2 3 4 5 6 7 8 9 10
| uni.getSystemInfo({ success: function(res) { console.log(res.windowWidth);
let info = uni.createSelectorQuery().select(".类名"); info.boundingClientRect(function(data) { console.log(data.width) }).exec() } });
|
uni-app中获取设备屏幕宽高已经获取某个元素的高度