小程序获取元素高度

…衆ロ難τιáo~ 提交于 2020-01-23 02:39:57

针对有定位元素
var query = wx.createSelectorQuery();
var scrollLeft = that.data.scrollLeft
query.select(’.stitTop’).boundingClientRect()
query.select(’.time’).boundingClientRect()
query.select(’.info’).boundingClientRect()
var myTime = setTimeout(function () {
query.exec((res) => {
console.log(res[0].height)
console.log(res[1].height)
console.log(res[2].height)
var shopListHeight = wx.getSystemInfoSync().windowHeight - (res[0].height + 15) - res[1].height - 54
var shopAdsTrue = shopListHeight - 110
console.log(shopListHeight)
that.setData({
scrollLeft: shopListHeight,
scrolllist: shopAdsTrue,
})
})
clearTimeout(myTime)
}, 1000)
(用定时器)
无定位
var query = wx.createSelectorQuery();
var scrollLeft = that.data.scrollLeft
query.select(’.stitTop’).boundingClientRect()
query.select(’.time’).boundingClientRect()
query.select(’.info’).boundingClientRect()
query.exec((res) => {
console.log(res[0].height)
console.log(res[1].height)
console.log(res[2].height)
var shopListHeight = wx.getSystemInfoSync().windowHeight - (res[0].height + 15) - res[1].height - 54
var shopAdsTrue = shopListHeight - 110
console.log(shopListHeight)
that.setData({
scrollLeft: shopListHeight,
scrolllist: shopAdsTrue,
})
})

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!