From b7d4224fd378d77dfe576704fb8e331381c7d0e8 Mon Sep 17 00:00:00 2001 From: Trae AI Date: Sat, 27 Dec 2025 11:46:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DiOS=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=A1=86=E9=9A=90=E8=97=8F=E6=97=B6=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=BC=BA=E8=A1=8C=E4=B8=8B=E6=BB=91=E5=92=8C=E8=BF=87?= =?UTF-8?q?=E6=B8=A1=E5=8A=A8=E7=94=BB=E4=B8=8D=E5=85=BC=E5=AE=B9=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.js | 36 +++++++++++++++++++++++++----------- pages/index/index.wxss | 23 +++++++++++------------ 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index ee9b811..3ffbeb6 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -870,37 +870,51 @@ Page({ }); }, - // 滚动事件处理 - 简化版本 + // 滚动事件处理 - 简化并修复iOS兼容性问题 onScroll: function(e) { const { scrollTop } = e.detail; - // 使用简单的阈值判断 - const shouldHide = scrollTop > 100; + // 使用更平滑的阈值判断,避免iOS上的抖动 + const threshold = 100; - // 只有当状态需要改变时才更新 - if (shouldHide !== this.data.isSearchBarFullyHidden) { + // 检查滚动方向 + const scrollingDown = scrollTop > this.data.lastScrollTop; + const scrollingUp = scrollTop < this.data.lastScrollTop; + + // 只在滚动超过阈值且方向改变时才更新状态 + if (scrollingDown && scrollTop > threshold && !this.data.isSearchBarFullyHidden) { + this.setData({ + isSearchBarFullyHidden: true, + lastScrollTop: scrollTop + }); + } else if (scrollingUp && scrollTop <= threshold && this.data.isSearchBarFullyHidden) { this.setData({ - isSearchBarFullyHidden: shouldHide, + isSearchBarFullyHidden: false, lastScrollTop: scrollTop }); } else { - // 只更新滚动位置 + // 其他情况只更新滚动位置 this.setData({ lastScrollTop: scrollTop }); } - // 回到顶部按钮显示逻辑 + // 回到顶部按钮显示逻辑 if (scrollTop > 300 && !this.data.showBackToTop) { this.setData({ showBackToTop: true }); } else if (scrollTop <= 300 && this.data.showBackToTop) { this.setData({ showBackToTop: false }); } - const app = getApp(); - if (app && app.globalData) { - app.globalData.showTabBar = true; + const { scrollHeight, clientHeight } = e.detail; + const distanceToBottom = scrollHeight - scrollTop - clientHeight; + + const app = getApp(); + if (!app || !app.globalData) { + return; } + + app.globalData.showTabBar = true; }, // 回到顶部 diff --git a/pages/index/index.wxss b/pages/index/index.wxss index 066db10..b7e2098 100644 --- a/pages/index/index.wxss +++ b/pages/index/index.wxss @@ -16,10 +16,10 @@ page { display: flex; flex-direction: column; box-sizing: border-box; - /* 移除背景色,让page的背景渐变显示出来 */ + background-color: #f8f8f8; } -/* 顶部搜索区域容器 - 保持紫色渐变背景 */ +/* 为整个容器添加修复 */ .top-section-container { position: fixed; top: 0; @@ -29,8 +29,8 @@ page { background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%); transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); transform: translateY(0); - will-change: transform; - -webkit-transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); + will-change: transform; /* iOS性能优化 */ + -webkit-transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); /* iOS兼容 */ } /* 隐藏时的状态 */ @@ -82,17 +82,15 @@ page { opacity: 0; } -/* 商品列表区域 - 调整位置 */ -.goods-section { - margin-top: 240rpx; /* 给搜索区域留出空间 */ - height: calc(100vh - 240rpx); - background: transparent; /* 透明背景,显示page的渐变 */ +/* 商品列表添加顶部内边距 */ +.goods-list { + padding-top: 240rpx; /* 与搜索区域高度匹配 */ + transition: padding-top 0.3s ease; } /* 当搜索框隐藏时调整内边距 */ -.top-section-container.top-hidden ~ .goods-section { - margin-top: 100rpx; - height: calc(100vh - 100rpx); +.top-section-container.top-hidden ~ .goods-list { + padding-top: 100rpx; /* 减少内边距 */ } /* 品种筛选区域调整 */ @@ -132,6 +130,7 @@ page { /* 确保滚动视图有正确的容器高度 */ .goods-section { + height: 100vh; position: relative; }