From 82cae8275927f941a29c458742ebbecd43fe18c3 Mon Sep 17 00:00:00 2001 From: Trae AI Date: Fri, 26 Dec 2025 17:26:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E6=90=9C=E7=B4=A2=E6=A1=86=E5=92=8C=E5=9B=9E?= =?UTF-8?q?=E5=88=B0=E9=A1=B6=E9=83=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 滚动时搜索框自动隐藏/显示 - 添加回到顶部按钮 - 优化滚动交互体验 --- pages/index/index.js | 55 ++++++++++++++++++++++++++++++++- pages/index/index.wxml | 15 +++++++-- pages/index/index.wxss | 70 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 136 insertions(+), 4 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index c07bc87..bfc0b74 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -21,6 +21,15 @@ Page({ sidebarBtnTop: 500, sidebarBtnHidden: false, + // 搜索区域相关 + searchSectionVisible: true, + lastScrollTop: 0, + isScrollLocked: false, + + // 回到顶部按钮 + showBackToTop: false, + scrollTop: 0, + // 搜索相关 searchKeyword: '', selectedRegion: '全国', @@ -772,7 +781,42 @@ Page({ // 滚动事件处理 onScroll: function(e) { - const { scrollTop, scrollHeight, clientHeight } = e.detail; + const { scrollTop } = e.detail; + + if (this.data.isScrollLocked) { + this.setData({ lastScrollTop: scrollTop }); + return; + } + + const scrollDirection = scrollTop > this.data.lastScrollTop ? 'down' : 'up'; + const scrollDelta = Math.abs(scrollTop - this.data.lastScrollTop); + + if (scrollDelta < 10) { + this.setData({ lastScrollTop: scrollTop }); + return; + } + + if (scrollDirection === 'down' && scrollTop > 100 && this.data.searchSectionVisible) { + this.setData({ searchSectionVisible: false, isScrollLocked: true }); + setTimeout(() => { + this.setData({ isScrollLocked: false }); + }, 300); + } else if (scrollDirection === 'up' && !this.data.searchSectionVisible && scrollTop < 50) { + this.setData({ searchSectionVisible: true, isScrollLocked: true }); + setTimeout(() => { + this.setData({ isScrollLocked: false }); + }, 300); + } + + if (scrollTop > 300 && !this.data.showBackToTop) { + this.setData({ showBackToTop: true }); + } else if (scrollTop <= 300 && this.data.showBackToTop) { + this.setData({ showBackToTop: false }); + } + + this.setData({ lastScrollTop: scrollTop }); + + const { scrollHeight, clientHeight } = e.detail; const distanceToBottom = scrollHeight - scrollTop - clientHeight; const app = getApp(); @@ -783,6 +827,15 @@ Page({ app.globalData.showTabBar = true; }, + // 回到顶部 + scrollToTop: function() { + this.setData({ + scrollTop: 0, + searchSectionVisible: true, + showBackToTop: false + }); + }, + // 上拉加载更多 onReachBottom: function() { if (this.data.hasMoreData && !this.data.loadingMore) { diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 2a1f895..e8f50e9 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -1,9 +1,9 @@ - 专业的鸡蛋现货交易平台 + 专业的鸡蛋现货交易平台 - + @@ -107,6 +107,15 @@ + + + + + 顶部 + 招商合作 @@ -155,9 +164,11 @@