修复缩略图区域 自动滚动偏差问题

This commit is contained in:
北枳 2025-08-26 00:18:15 +08:00
parent 2dc7c5e616
commit f9c1a70b8f

View File

@ -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]);