获取微信小程序元素或屏幕高度

本人小白一枚,记录开发中碰到的问题
要获取微信小程序内元素高度,可以使用

const query = wx.createSelectorQuery() //定义query
query.select('#txt_medium').boundingClientRect() //获取元素参数
query.exec((res) => {
    
    
      console.log(res) //可以得到元素高度、距离顶部的top值、宽度等,单位为px
})

获取微信小程序屏幕高度和宽度,单位:px

height: wx.getSystemInfoSync().windowHeight,
width: wx.getSystemInfoSync().windowWidth

猜你喜欢

转载自blog.csdn.net/weixin_50147372/article/details/111994166