forked from 77media/video-flow
修复缩略图区域 自动滚动偏差问题
This commit is contained in:
parent
2dc7c5e616
commit
f9c1a70b8f
@ -30,14 +30,20 @@ export function ThumbnailGrid({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (thumbnailsRef.current) {
|
if (thumbnailsRef.current) {
|
||||||
const container = thumbnailsRef.current;
|
const container = thumbnailsRef.current;
|
||||||
const thumbnailWidth = container.offsetWidth / 4; // 每个缩略图宽度(包含间距)
|
const thumbnails = container.children;
|
||||||
const scrollPosition = currentSketchIndex * thumbnailWidth;
|
|
||||||
|
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({
|
container.scrollTo({
|
||||||
left: scrollPosition,
|
left: scrollPosition,
|
||||||
behavior: 'smooth'
|
behavior: 'smooth'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, [currentSketchIndex]);
|
}, [currentSketchIndex]);
|
||||||
|
|
||||||
// 获取当前阶段的数据数组
|
// 获取当前阶段的数据数组
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user