forked from 77media/video-flow
修复缩略图区域 自动滚动偏差问题
This commit is contained in:
parent
2dc7c5e616
commit
f9c1a70b8f
@ -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]);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user