在使用uniapp开发小程序、app时经常需要获取View等各类元素的高度,现将方法分享
在使用uniapp开发小程序、app时经常需要获取View等各类元素的高度,现将方法分享
uni.getSystemInfo({
success: function(res) { // res - 各种参数
console.log(res.windowWidth); // 屏幕的宽度
let info = uni.createSelectorQuery().select(".类名");
info.boundingClientRect(function(data) { //data - 各种参数
console.log(data.width) // 获取元素宽度
}).exec()
}
});