mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-24 16:58:47 +01:00
Got to be picky about the smooth vs jump scroll
This commit is contained in:
parent
1fed35f674
commit
613e77e43f
1 changed files with 5 additions and 2 deletions
|
@ -22,13 +22,16 @@ function MediaModal({
|
|||
useLayoutEffect(() => {
|
||||
carouselFocusItem.current?.scrollIntoView();
|
||||
}, []);
|
||||
const prevStatusID = useRef(statusID);
|
||||
useEffect(() => {
|
||||
const scrollLeft = index * carouselRef.current.clientWidth;
|
||||
const differentStatusID = prevStatusID.current !== statusID;
|
||||
if (differentStatusID) prevStatusID.current = statusID;
|
||||
carouselRef.current.scrollTo({
|
||||
left: scrollLeft,
|
||||
behavior: 'smooth',
|
||||
behavior: differentStatusID ? 'auto' : 'smooth',
|
||||
});
|
||||
}, [index]);
|
||||
}, [index, statusID]);
|
||||
|
||||
const [showControls, setShowControls] = useState(true);
|
||||
|
||||
|
|
Loading…
Reference in a new issue