微信小程序获取循环数据的高度

微信小程序获取循环数据的高度

.js

Page({
  data: {
  },
  onLoad: function (options) {
    let that = this
    const query = wx.createSelectorQuery()
    query.select('#productServe').boundingClientRect() 
    query.selectViewport().scrollOffset() 
    query.exec((res) => {
      console.log(res[1].scrollHeight)
      that.setData({
        heightx: res[1].scrollHeight//获取到了id是productServe的高度
      })
    })
  },
})

.wxml

<view style="height:{{heightx}}px;">
<image wx:for="{{10}}" wx:key src="/img/1.jpg" id="productServe" style="width:100%;"></image> 
</view>

有什么问题欢迎评论留言,我会及时回复你的

原创文章 75 获赞 87 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_43764578/article/details/102859994
今日推荐