Browse Source

添加下滑自动收缩侧边栏按钮功能

pull/1/head
徐飞洋 2 months ago
parent
commit
fd0dc45b7d
  1. 13
      pages/index/index.js

13
pages/index/index.js

@ -1127,6 +1127,9 @@ Page({
const threshold = 50;
const backToTopThreshold = 300;
const lastScrollTop = this.data.lastScrollTop || 0;
const isScrollingDown = scrollTop > lastScrollTop;
let needUpdate = false;
const updates = {
lastScrollTop: scrollTop
@ -1135,7 +1138,15 @@ Page({
// 搜索框始终固定显示,不做隐藏处理
// 侧边栏按钮显示逻辑
if (scrollTop <= threshold && this.data.sidebarBtnHidden) {
// 下滑时隐藏按钮(除非用户未手动隐藏过且在顶部)
if (isScrollingDown && scrollTop > threshold && !this.data.sidebarBtnHidden) {
updates.sidebarBtnHidden = true;
needUpdate = true;
wx.setStorageSync('sidebarBtnHidden', true);
wx.setStorageSync('userManuallyHidden', true);
}
// 上滑到顶部时显示按钮
else if (scrollTop <= threshold && this.data.sidebarBtnHidden && !this.data.userManuallyHidden) {
updates.sidebarBtnHidden = false;
needUpdate = true;
wx.setStorageSync('sidebarBtnHidden', false);

Loading…
Cancel
Save