亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長(zhǎng)資訊網(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、在頁(yè)面渲染完成OnReady回調(diào),獲取元素高度時(shí),如果不加定時(shí)器,獲取的元素的高度還是沒(méi)渲染完異步數(shù)據(jù)前的高度。故需要加定時(shí)器

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

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

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