The WeChat applet monitors the user's sliding up or down method: first define the hidden used by the two modules that need to be switched; then define two variables in the data to accept the changed true or false; then use the data data It is used to determine whether the module displays hidden variables; finally, it is enough to collect the monitoring results.
Methods for WeChat applet to monitor whether the user slides up or down:
Idea: first monitor whether the user slides up or down It is still sliding. After listening to the results, change the variables in the data data used to determine whether the module is displayed or hidden. The two modules that need to be switched use hidden. Two variables are defined in the data to accept the changed true or false.
The code is:
hidden='{{bottom}}' hidden='{{top}}' data{ //初始化状态 top:true, bottom:false, } //判断浏览器滚动条上下滚动 if (t.scrollTop > a.data.scrollTop || t.scrollTop == wx.getSystemInfoSync().windowHeight) { console.log('向下滚动'); // 改变显示隐藏的状态 a.setData({ bottom: true, top: false }) console.log(a.data.bottom) } else { console.log('向上滚动'); a.setData({ bottom: false, top: true }) console.log(a.data.bottom) }
Related learning recommendations: WeChat Mini Program Development Tutorial
The above is the detailed content of How does a WeChat applet monitor users' scrolling up or down?. For more information, please follow other related articles on the PHP Chinese website!