uniapp获取到当前设备高度与宽度和当前元素距离顶部的距离

发布时间 2023-04-26 17:27:29作者: 爱吃变态辣

获取到当前设备的宽度和高度

uni.getSystemInfo({
success: function (res) {
console.log(res.windowHeight)

console.log(res.windowWidth)
}
})

 

当前元素距离顶部的距离

uni.createSelectorQuery().select('.your-selector')

  .boundingClientRect(function(rect){
    console.log(rect.top);  // 元素上边距离屏幕顶部的高度
  }).exec();