小程序如何获取页面滚动距离

在小程序中使用onPageScroll()方法,通过e.scrollTop获取页面滚动距离。

//获取下拉距离
    onPageScroll: function (res) {
    
    
        console.log(res);
        let that = this
        let scrollTop = res.scrollTop
        that.setData({
    
    
            scrollTop
        })
        if (scrollTop >= 192) {
    
    
            that.setData({
    
    
                fixedScrollTop: true
            })
        } else {
    
    
            that.setData({
    
    
                fixedScrollTop: false
            })
        }
    },

猜你喜欢

转载自blog.csdn.net/weixin_45357661/article/details/130010215