uniapp 获取元素高度 距离顶部高度等

let _this=this
		   let height=""
		   const query = uni.createSelectorQuery()
		   query.select('#u-dropdown').boundingClientRect()
		   query.selectViewport().scrollOffset()
		   query.exec(function(res){
		    // debugger
		    res[0].top       // #the-id节点的上边界坐标
		    res[1].scrollTop // 显示区域的竖直滚动位置
		    // _this.height=res.windowHeight-res[0].top +'px'
		    // =_this.height
		    height=uni.getSystemInfoSync().screenHeight
		    _this.viewHeight=height-res[0].top-res[0].height
			_this.contentStyle={
				zIndex: -1,
				opacity: 0,
				height:_this.viewHeight+'px'
			}
		    // console.log('打印高度',_this.viewHeight);
		    // console.log('打印demo的元素的信息',res);
		   })
		  }

  

posted @ 2020-08-28 10:36  麦麦芽  阅读(7335)  评论(0)    收藏  举报