update ui

This commit is contained in:
2025-11-13 16:17:32 +08:00
parent 5aa0507a65
commit 5ddf8d3c09
2 changed files with 45 additions and 20 deletions

View File

@@ -120,10 +120,15 @@ const Community = () => {
};
// ⚡ 首次进入页面时滚动到内容区域(考虑导航栏高度)
const hasScrolled = useRef(false);
useEffect(() => {
// 只在第一次挂载时执行滚动
if (hasScrolled.current) return;
// 延迟执行确保DOM已完全渲染
const timer = setTimeout(() => {
if (containerRef.current) {
hasScrolled.current = true;
// 滚动到容器顶部,自动考虑导航栏的高度
containerRef.current.scrollIntoView({
behavior: 'auto',
@@ -131,7 +136,7 @@ const Community = () => {
inline: 'nearest'
});
}
}, 0);
}, 100);
return () => clearTimeout(timer);
}, []); // 空依赖数组,只在组件挂载时执行一次