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

mac2025-09-08  13

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

.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>

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

最新回复(0)