This commit is contained in:
张成
2025-11-09 21:10:45 +08:00
parent 0090fc45c6
commit 52622dec92
6 changed files with 55 additions and 40 deletions

View File

@@ -3,7 +3,8 @@
top: 0; top: 0;
left: 0; left: 0;
overflow: hidden; overflow: hidden;
z-index: 9991; z-index: 99;
width: 100%; width: 100%;
// 背景颜色通过 style 动态设置,默认透明 // 背景颜色通过 style 动态设置,默认透明
box-shadow: none;
} }

View File

@@ -4,10 +4,11 @@
.nut-menu-bar { .nut-menu-bar {
--nutui-menu-bar-line-height: 30px; --nutui-menu-bar-line-height: 30px;
background-color: unset; background-color: #fafafa;
box-shadow: unset; box-shadow: unset;
// padding: 0 15px; // padding: 0 15px;
gap: 5px; gap: 5px;
justify-content: flex-start;
} }
.nut-menu-title { .nut-menu-title {
@@ -33,8 +34,12 @@
.nut-menu-container-wrap { .nut-menu-container-wrap {
width: 100vw; width: 100vw;
left: 0 !important;
margin-left: -15px !important;
border-bottom-left-radius: 30px; border-bottom-left-radius: 30px;
border-bottom-right-radius: 30px; border-bottom-right-radius: 30px;
background-color: #fafafa !important;
z-index: 1000 !important;
} }
.positionWrap { .positionWrap {

View File

@@ -124,7 +124,7 @@ const ListHeader = (props: IProps) => {
}; };
return ( return (
<CustomNavbar> <CustomNavbar backgroundColor="#fafafa">
<View className="listNavWrapper"> <View className="listNavWrapper">
{/* 首页logo 导航*/} {/* 首页logo 导航*/}
<View <View

View File

@@ -1,6 +1,6 @@
:global { :global {
.guide-bar { .guide-bar {
z-index: 9990; z-index: 999;
} }
} }
@@ -89,14 +89,13 @@
.fixedHeader { .fixedHeader {
position: sticky; position: sticky;
top: 0; top: 0;
z-index: 100; z-index: 90;
background-color: #fff;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
.listTopSearchWrapper { .listTopSearchWrapper {
background-color: #fff; background-color: #fafafa;
// 使用 margin-top 负值来控制可见性,保持元素高度不变,筛选项位置固定 // 使用 margin-top 负值来控制可见性,保持元素高度不变,筛选项位置固定
transition: margin-top 0.25s cubic-bezier(0.4, 0, 0.2, 1), transition: margin-top 0.25s cubic-bezier(0.4, 0, 0.2, 1),
opacity 0.2s ease-out; opacity 0.2s ease-out;
@@ -121,9 +120,10 @@
display: flex; display: flex;
box-sizing: border-box; box-sizing: border-box;
align-items: center; align-items: center;
padding: 0 15px 10px 15px; // 上0 左右15px 下10px与搜索框左右对齐下边距一致 padding: 0 15px 10px 15px;
// 上0 左右15px 下10px与搜索框左右对齐下边距一致
gap: 5px; gap: 5px;
background-color: #fff; background-color: #fafafa;
} }
.listScrollView { .listScrollView {
@@ -188,5 +188,5 @@
} }
.guideBarList { .guideBarList {
z-index: 99; z-index: 999;
} }

View File

@@ -68,6 +68,7 @@ const ListPage = () => {
const scrollDirectionRef = useRef<'up' | 'down' | null>(null); const scrollDirectionRef = useRef<'up' | 'down' | null>(null);
const lastScrollTimeRef = useRef(Date.now()); const lastScrollTimeRef = useRef(Date.now());
const loadingMoreRef = useRef(false); // 防止重复加载更多 const loadingMoreRef = useRef(false); // 防止重复加载更多
const scrollStartPositionRef = useRef(0); // 记录开始滚动的位置
const [showSearchBar, setShowSearchBar] = useState(true); // 控制搜索框显示/隐藏(筛选始终显示) const [showSearchBar, setShowSearchBar] = useState(true); // 控制搜索框显示/隐藏(筛选始终显示)
// ScrollView 滚动处理函数 // ScrollView 滚动处理函数
@@ -78,49 +79,57 @@ const ListPage = () => {
const currentTime = Date.now(); const currentTime = Date.now();
const timeDiff = currentTime - lastScrollTimeRef.current; const timeDiff = currentTime - lastScrollTimeRef.current;
// 节流:如果时间差太小,跳过本次处理 // 节流:提高到100ms减少触发频率
if (timeDiff < 16) return; // 约60fps避免过于频繁的计算 if (timeDiff < 100) return;
// 计算滚动距离 // 计算滚动距离
const scrollDiff = currentScrollTop - lastScrollTop; const scrollDiff = currentScrollTop - lastScrollTop;
// 判断滚动方向(提高阈值避免微小滚动误判 // 判断滚动方向(提高阈值到15px
let newDirection = scrollDirectionRef.current; let newDirection = scrollDirectionRef.current;
if (scrollDiff > 5) { if (Math.abs(scrollDiff) > 15) {
if (scrollDiff > 0) {
// 方向改变时,记录新的起始位置
if (newDirection !== 'up') {
scrollStartPositionRef.current = lastScrollTop;
}
newDirection = 'up'; newDirection = 'up';
} else if (scrollDiff < -5) { } else {
// 方向改变时,记录新的起始位置
if (newDirection !== 'down') {
scrollStartPositionRef.current = lastScrollTop;
}
newDirection = 'down'; newDirection = 'down';
} }
scrollDirectionRef.current = newDirection; scrollDirectionRef.current = newDirection;
// 清除之前的定时器
if (scrollTimeoutRef.current) {
clearTimeout(scrollTimeoutRef.current);
} }
// 滚动阈值(提高阈值减少误触发) // 计算从开始滚动到现在的累计距离
const threshold = 80; const totalScrollDistance = Math.abs(currentScrollTop - scrollStartPositionRef.current);
if (newDirection === 'up' && currentScrollTop > threshold) { // 滚动阈值
// 上滑超过阈值,隐藏搜索框 const positionThreshold = 120; // 需要滚动到距离顶部120px
if (showSearchBar) { const distanceThreshold = 80; // 需要连续滚动80px才触发
if (newDirection === 'up' && currentScrollTop > positionThreshold && totalScrollDistance > distanceThreshold) {
// 上滑超过阈值,且连续滚动距离足够,隐藏搜索框
if (showSearchBar || !isShowInputCustomerNavBar) {
setShowSearchBar(false); setShowSearchBar(false);
}
if (!isShowInputCustomerNavBar) {
updateListPageState({ updateListPageState({
isShowInputCustomerNavBar: true, isShowInputCustomerNavBar: true,
}); });
// 重置起始位置
scrollStartPositionRef.current = currentScrollTop;
} }
} else if (newDirection === 'down' || currentScrollTop <= threshold) { } else if ((newDirection === 'down' && totalScrollDistance > distanceThreshold) || currentScrollTop <= positionThreshold) {
// 下滑回到顶部,显示搜索框 // 下滑且连续滚动距离足够,或者回到顶部附近,显示搜索框
if (!showSearchBar) { if (!showSearchBar || isShowInputCustomerNavBar) {
setShowSearchBar(true); setShowSearchBar(true);
}
if (isShowInputCustomerNavBar) {
updateListPageState({ updateListPageState({
isShowInputCustomerNavBar: false, isShowInputCustomerNavBar: false,
}); });
// 重置起始位置
scrollStartPositionRef.current = currentScrollTop;
} }
} }

View File

@@ -12,7 +12,7 @@
padding: 5px 15px 10px 15px; padding: 5px 15px 10px 15px;
position: sticky; position: sticky;
top: -1px; top: -1px;
background-color: #fefefe; background-color: #fafafa;
z-index: 123; z-index: 123;
.nut-menu-bar { .nut-menu-bar {