久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      微信小程序如何獲取元素的高度

      微信小程序如何獲取元素的高度

      微信小程序如何獲取元素的高度

      1、獲取元素的高度(px單位):

      let query = wx.createSelectorQuery(); query.select('.content').boundingClientRect(rect=>{   let height = rect.height;   console.log(height); }).exec();

      2、獲取元素的高度(rpx單位),使用寬高比換算獲得:(以下的750是該元素的寬度,單位是rpx的)

      let query = wx.createSelectorQuery(); query.select('.content').boundingClientRect(rect=>{   let clientHeight = rect.height;   let clientWidth = rect.width;   let ratio = 750 / clientWidth;   let height = clientHeight * ratio;   console.log(height); }).exec();

      3、在頁面渲染完成OnReady回調(diào),獲取元素高度時,如果不加定時器,獲取的元素的高度還是沒渲染完異步數(shù)據(jù)前的高度。故需要加定時器

      onReady () {     setTimeout(() => {     let query = wx.createSelectorQuery();     query.select('.content').boundingClientRect(rect=>{         let height = rect.height;         console.log(height);         }).exec();     }, 300) }

      PHP中文網(wǎng),大量免費小程序開發(fā)教程,歡迎學(xué)習(xí)!

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號