Skip to content

Commit

Permalink
Merge pull request #171 from daodaoedu/feature/learning-marathon
Browse files Browse the repository at this point in the history
fix: safari scroll width bug
  • Loading branch information
JohnsonMao authored Dec 16, 2024
2 parents 2c47415 + 442643b commit 5a83b99
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions components/Marathon/Mentors.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,12 @@ 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 currentTranslateX = currentMentor * 301;
if (window.innerWidth + currentTranslateX > mentorsRef.current?.scrollWidth) {
return { translateX: mentorsRef.current?.scrollWidth - window.innerWidth, isEnd: true };
if (window.innerWidth + currentTranslateX > mentorsWidth) {
return { translateX: mentorsWidth - window.innerWidth, isEnd: true };
}
return { translateX: currentTranslateX, isEnd: false };
}, [currentMentor]);
Expand Down

0 comments on commit 5a83b99

Please sign in to comment.