获取某个页面元素的rect属性
uni.createSelectorQuery().select('.card');
boundingClientRect
<view class="card"></view>
// 获取卡片高度
getBtnStyle() {
let _this = this
let obj = uni.createSelectorQuery().select('.card')
//obj包括component,selector,selectorQuery等属性
obj.boundingClientRect(function(data) {
// data包括dataset,top,right,bottom,left,width,height等属性
_this.btnStyle = "line-height:" + data.height + "rpx";
_this.$forceUpdate()
}).exec()
},
注意:
- 这个方法要在页面渲染完成之后才可以调用
- 如果想要获取屏幕的其他信息,可以使用uni.getSystemInfo;
网友评论