解决方案@H_301_4@
1.用到微信小程序API@H_301_4@
获取页面实际高度 nodesRef.boundingClientRect([callback])
监听用户滑动页面事件onPageScroll。
2.获取页面实际高度@H_301_4@
Box">
3.监听用户滑动页面事件@H_301_4@
用户滑动页面事件
onPageScroll: function(e) {
if (e.scrollTop <= 0) {
// 滚动到最顶部
e.scrollTop = 0;
} else if (e.scrollTop > this.data.scrollHeight) {
// 滚动到最底部
e.scrollTop = this.data.scrollHeight;
}
if (e.scrollTop > this.data.scrollTop || e.scrollTop >= this.data.scrollHeight) {
//向下滚动
console.log('向下 ',this.data.scrollHeight)
} else {
//向上滚动
console.log('向上滚动 ',this.data.scrollHeight)
}
//给scrollTop重新赋值
this.setData({
scrollTop: e.scrollTop
})
},
if (e.scrollTop <= 0) {
// 滚动到最顶部
e.scrollTop = 0;
} else if (e.scrollTop > this.data.scrollHeight) {
// 滚动到最底部
e.scrollTop = this.data.scrollHeight;
}
if (e.scrollTop > this.data.scrollTop || e.scrollTop >= this.data.scrollHeight) {
//向下滚动
console.log('向下 ',this.data.scrollHeight)
} else {
//向上滚动
console.log('向上滚动 ',this.data.scrollHeight)
}
//给scrollTop重新赋值
this.setData({
scrollTop: e.scrollTop
})
},
PS:微信小程序滚动到某个位置改变效果@H_301_4@
Some of the words
文件
//滚动监听
scroll: function (e) {
this.setData({
scrollTop:e.detail.scrollTop
})
}
其中,variable为全局变量,class1、class2即为相应的css