关于scroll-view 的属性upper-threshold触发问题
发布于 3 年前 作者 sqiao 9546 次浏览 来自 问答

文档说明:

代码如下:

wxml:
<scroll-view scroll-y bindscrolltoupper="bindscrolltoupper" scroll-top="{{topNum}}" scroll-with-animation="{{true}}" upper-threshold="50" >
</scroll-view>

js:
// 触顶方法,当滚动条触顶时显示图表
bindscrolltoupper (e) { 
  console.log('触发bindscrolltoupper')
  if (this.data.PageCur == 'statistics') {
    this.selectComponent("#statistics").showCharts()
   }
},

// 当滚动条距离顶部50时,触发显示小火箭
scrolltoupper() {
  this.setData({
     topVisual: true
    })
}

在提问之前我看了其他的文章,有的人说upper-threshold属性触发的事件就是bindscrolltoupper绑定的事件

但是在滚动的时候并没有触发bindscrolltoupper绑定的事件,bindscrolltoupper绑定的事件依然是在触顶时才会执行,那么文档上说的 距顶部/左边多远时,触发 scrolltoupper 事件,到底是怎么触发的?

我的期望是upper-threshold能触发我的scrolltoupper方法

1 回复

虽然upper-threshold属性的触发问题不清楚

只能改变思路了

使用bindscroll属性绑定方法,取代upper-threshold属性,在bindscroll中判断滚动条高度大于多少时执行逻辑

文档说明:

代码如下:

wxml:
<scroll-view scroll-y bindscrolltoupper="bindscrolltoupper" scroll-top="{{topNum}}" scroll-with-animation="{{true}}" bindscroll="binddragging" >
</scroll-view>

js:
bindscroll(e) {
  if (e.detail.scrollTop >= 50) {
    this.scrolltoupper()
  }
}
  
回到顶部