diff --git a/components/pages/work-flow/thumbnail-grid.tsx b/components/pages/work-flow/thumbnail-grid.tsx index 3e2d1fd..b089323 100644 --- a/components/pages/work-flow/thumbnail-grid.tsx +++ b/components/pages/work-flow/thumbnail-grid.tsx @@ -30,13 +30,19 @@ export function ThumbnailGrid({ useEffect(() => { if (thumbnailsRef.current) { const container = thumbnailsRef.current; - const thumbnailWidth = container.offsetWidth / 4; // 每个缩略图宽度(包含间距) - const scrollPosition = currentSketchIndex * thumbnailWidth; + const thumbnails = container.children; + + if (currentSketchIndex >= 0 && currentSketchIndex < thumbnails.length) { + const thumbnail = thumbnails[currentSketchIndex] as HTMLElement; + const containerLeft = container.getBoundingClientRect().left; + const thumbnailLeft = thumbnail.getBoundingClientRect().left; + const scrollPosition = container.scrollLeft + (thumbnailLeft - containerLeft); - container.scrollTo({ - left: scrollPosition, - behavior: 'smooth' - }); + container.scrollTo({ + left: scrollPosition, + behavior: 'smooth' + }); + } } }, [currentSketchIndex]);