通过相交 wx.createIntersectionObserver() 来判断
发布于 5 年前 作者 xiuying55 913 次浏览 来自 问答

通过相交来判断是否在可视区域内,页面滚动,苹果系统小程序不能时时监听变化,安卓的可以时时监听res返回的值,苹果的需要再滚动完停止了,才会返回res值

wx.createIntersectionObserver().relativeToViewport({ bottom: 100 }).observe(’.select-area’, (res) => {

if (res.intersectionRect.bottom==0) {

this.setData({

isfloat:true

})

}

else {

this.setData({

isfloat: false

})

}

console.log(res)

})

4 回复

这问题还没解决?

你好,请问这个问题解决了吗

提供一下出现问题的机型和微信版本,以及能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

onLoad: function (options) {

    wx.createIntersectionObserver().relativeToViewport({ bottom: 100 }).observe(’.select-area’, (res) => {

    console.log(res)

    })

}

在ios里面,滚动监听会延时,每次都是滚动完停止了页面不动了,才会打印console.log(res)

回到顶部