//监听屏幕滚动 判断上下滚动
onPageScroll: function (ev) {
var _this = this;
//当滚动的top值最大或者最小时,为什么要做这一步是由于在手机实测小程序的时候会发生滚动条回弹,所以为了解决回弹,设置默认最大最小值
if (ev.scrollTop <= 0) {
ev.scrollTop = 0;
console.log("到顶部")
this.setData({
comShow: false
});
} else if (ev.scrollTop > wx.getSystemInfoSync().windowHeight) {
ev.scrollTop = wx.getSystemInfoSync().windowHeight;
}
//判断浏览器滚动条上下滚动
if (ev.scrollTop > this.data.scrollTop || ev.scrollTop == wx.getSystemInfoSync().windowHeight) {
console.log('向下滚动');
this.setData({
comShow: true
});
} else {
console.log('向上滚动');
// this.setData({
// comShow: false
// });
}
//给scrollTop重新赋值
setTimeout(function () {
_this.setData({
scrollTop: ev.scrollTop
})
}, 0)
},
参考链接:https://blog.csdn.net/qq_26383975/article/details/107317996?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522161966626116780262591071%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=161966626116780262591071&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_v2~rank_v29-12-107317996.pc_search_result_no_baidu_js&utm_term=%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%88%A4%E6%96%AD%E6%BB%9A%E5%8A%A8%E5%88%B0%E9%A1%B6%E9%83%A8