1
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
:global {
|
||||
.guide-bar {
|
||||
z-index: 9990;
|
||||
z-index: 999;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,14 +89,13 @@
|
||||
.fixedHeader {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 100;
|
||||
background-color: #fff;
|
||||
z-index: 90;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.listTopSearchWrapper {
|
||||
background-color: #fff;
|
||||
background-color: #fafafa;
|
||||
// 使用 margin-top 负值来控制可见性,保持元素高度不变,筛选项位置固定
|
||||
transition: margin-top 0.25s cubic-bezier(0.4, 0, 0.2, 1),
|
||||
opacity 0.2s ease-out;
|
||||
@@ -121,9 +120,10 @@
|
||||
display: flex;
|
||||
box-sizing: border-box;
|
||||
align-items: center;
|
||||
padding: 0 15px 10px 15px; // 上0 左右15px 下10px(与搜索框左右对齐,下边距一致)
|
||||
padding: 0 15px 10px 15px;
|
||||
// 上0 左右15px 下10px(与搜索框左右对齐,下边距一致)
|
||||
gap: 5px;
|
||||
background-color: #fff;
|
||||
background-color: #fafafa;
|
||||
}
|
||||
|
||||
.listScrollView {
|
||||
@@ -188,5 +188,5 @@
|
||||
}
|
||||
|
||||
.guideBarList {
|
||||
z-index: 99;
|
||||
z-index: 999;
|
||||
}
|
||||
@@ -68,6 +68,7 @@ const ListPage = () => {
|
||||
const scrollDirectionRef = useRef<'up' | 'down' | null>(null);
|
||||
const lastScrollTimeRef = useRef(Date.now());
|
||||
const loadingMoreRef = useRef(false); // 防止重复加载更多
|
||||
const scrollStartPositionRef = useRef(0); // 记录开始滚动的位置
|
||||
const [showSearchBar, setShowSearchBar] = useState(true); // 控制搜索框显示/隐藏(筛选始终显示)
|
||||
|
||||
// ScrollView 滚动处理函数
|
||||
@@ -78,49 +79,57 @@ const ListPage = () => {
|
||||
const currentTime = Date.now();
|
||||
const timeDiff = currentTime - lastScrollTimeRef.current;
|
||||
|
||||
// 节流:如果时间差太小,跳过本次处理
|
||||
if (timeDiff < 16) return; // 约60fps,避免过于频繁的计算
|
||||
// 节流:提高到100ms,减少触发频率
|
||||
if (timeDiff < 100) return;
|
||||
|
||||
// 计算滚动距离
|
||||
const scrollDiff = currentScrollTop - lastScrollTop;
|
||||
|
||||
// 判断滚动方向(提高阈值避免微小滚动误判)
|
||||
// 判断滚动方向(提高阈值到15px)
|
||||
let newDirection = scrollDirectionRef.current;
|
||||
if (scrollDiff > 5) {
|
||||
newDirection = 'up';
|
||||
} else if (scrollDiff < -5) {
|
||||
newDirection = 'down';
|
||||
}
|
||||
|
||||
scrollDirectionRef.current = newDirection;
|
||||
|
||||
// 清除之前的定时器
|
||||
if (scrollTimeoutRef.current) {
|
||||
clearTimeout(scrollTimeoutRef.current);
|
||||
}
|
||||
|
||||
// 滚动阈值(提高阈值减少误触发)
|
||||
const threshold = 80;
|
||||
|
||||
if (newDirection === 'up' && currentScrollTop > threshold) {
|
||||
// 上滑超过阈值,隐藏搜索框
|
||||
if (showSearchBar) {
|
||||
setShowSearchBar(false);
|
||||
if (Math.abs(scrollDiff) > 15) {
|
||||
if (scrollDiff > 0) {
|
||||
// 方向改变时,记录新的起始位置
|
||||
if (newDirection !== 'up') {
|
||||
scrollStartPositionRef.current = lastScrollTop;
|
||||
}
|
||||
newDirection = 'up';
|
||||
} else {
|
||||
// 方向改变时,记录新的起始位置
|
||||
if (newDirection !== 'down') {
|
||||
scrollStartPositionRef.current = lastScrollTop;
|
||||
}
|
||||
newDirection = 'down';
|
||||
}
|
||||
if (!isShowInputCustomerNavBar) {
|
||||
scrollDirectionRef.current = newDirection;
|
||||
}
|
||||
|
||||
// 计算从开始滚动到现在的累计距离
|
||||
const totalScrollDistance = Math.abs(currentScrollTop - scrollStartPositionRef.current);
|
||||
|
||||
// 滚动阈值
|
||||
const positionThreshold = 120; // 需要滚动到距离顶部120px
|
||||
const distanceThreshold = 80; // 需要连续滚动80px才触发
|
||||
|
||||
if (newDirection === 'up' && currentScrollTop > positionThreshold && totalScrollDistance > distanceThreshold) {
|
||||
// 上滑超过阈值,且连续滚动距离足够,隐藏搜索框
|
||||
if (showSearchBar || !isShowInputCustomerNavBar) {
|
||||
setShowSearchBar(false);
|
||||
updateListPageState({
|
||||
isShowInputCustomerNavBar: true,
|
||||
});
|
||||
// 重置起始位置
|
||||
scrollStartPositionRef.current = currentScrollTop;
|
||||
}
|
||||
} else if (newDirection === 'down' || currentScrollTop <= threshold) {
|
||||
// 下滑或回到顶部,显示搜索框
|
||||
if (!showSearchBar) {
|
||||
} else if ((newDirection === 'down' && totalScrollDistance > distanceThreshold) || currentScrollTop <= positionThreshold) {
|
||||
// 下滑且连续滚动距离足够,或者回到顶部附近,显示搜索框
|
||||
if (!showSearchBar || isShowInputCustomerNavBar) {
|
||||
setShowSearchBar(true);
|
||||
}
|
||||
if (isShowInputCustomerNavBar) {
|
||||
updateListPageState({
|
||||
isShowInputCustomerNavBar: false,
|
||||
});
|
||||
// 重置起始位置
|
||||
scrollStartPositionRef.current = currentScrollTop;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
padding: 5px 15px 10px 15px;
|
||||
position: sticky;
|
||||
top: -1px;
|
||||
background-color: #fefefe;
|
||||
background-color: #fafafa;
|
||||
z-index: 123;
|
||||
|
||||
.nut-menu-bar {
|
||||
|
||||
Reference in New Issue
Block a user