scroll-view中的item高度不一,但是不设置高度就无法触发滑动监听
发布于 6 年前 作者 qiang08 2213 次浏览 来自 问答

scroll-view中的item高度不一,所以没办法给一个固定的高度,但是不设置固定的高度就无法触发滑动监听bindscrolltoupper,请问有没有办法解决这个问题

4 回复

bindscrolltoupper  滚动加载了一页, 在加载第二页的时候, 需要scroll-view上划一点到顶部的距离才能触发,  iOS 比较明显,大概率出现这种情况

<scroll-view id=“chatScrollView” scroll-y style=“height: {{height}}px;” upper-threshold=“100” bindscroll=“scroll” bindscrolltoupper=“upper” scroll-top="{{scrollTop}}" scroll-into-view="{{toView}}">

scroll-view 不设高度,滑动区域就和内容一样大,

等于滑动的是 body,而非 scroll-view,所以最好 scroll-view 能固定高度。

需求不太清楚,感觉是类似 max-height 的效果,

如果是这样的话恐怕只能 js 解决了,套个 .wrap 然后用 boundingClientRect 来获取高度。

wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 90;
 
        that.setData({
          winHeight: calc
        });
      }
    });

onLond中加入这行代码  data中给个winHeight ,wxml中 scroll-view 标签style中设置height

<scroll-view scroll-y="true" style='height:{{winHeight-30}}rpx;'>

可以用加减法控制显示高度

就以最大的高度为准呗,这个距离大小,只是影响什么时候加载更多数据吧。除非你的高度差别非常大,大的基本快全屏了,小的只有几十rpx高。

回到顶部