From 7f6e601ee2c1e8d272064caab5f20fb5b0634776 Mon Sep 17 00:00:00 2001 From: Johnson Mao <86179381+JohnsonMao@users.noreply.github.com> Date: Mon, 16 Dec 2024 22:33:34 +0800 Subject: [PATCH] fix: mentors carousel behavior issues --- components/Marathon/Mentors.jsx | 56 +++++++++++++++++---------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/components/Marathon/Mentors.jsx b/components/Marathon/Mentors.jsx index 14ed4eea..96135e56 100644 --- a/components/Marathon/Mentors.jsx +++ b/components/Marathon/Mentors.jsx @@ -205,12 +205,10 @@ const Mentors = () => { const [touchStartX, setTouchStartX] = useState(null); const timer = useRef(null); const { translateX, isEnd } = useMemo(() => { - // 因為 Safari 使用父層的 scrollWidth 再搭配 transform 時,scrollWidth 會越變越小,所以改用計算寬度 - // 計算 mentors 的寬度,包含了 gap 和 padding - const mentorsWidth = mentorsRef.current?.children?.[0]?.clientWidth * mentors.length + 16 * (mentors.length - 1) + 48; + const mentorsWidth = mentorsRef.current?.scrollWidth; const currentTranslateX = currentMentor * 301; if (window.innerWidth + currentTranslateX > mentorsWidth) { - return { translateX: mentorsWidth - window.innerWidth, isEnd: true }; + return { translateX: mentorsWidth - window.innerWidth + 16, isEnd: true }; } return { translateX: currentTranslateX, isEnd: false }; }, [currentMentor]); @@ -292,34 +290,38 @@ const Mentors = () => {