fix: anchor current practice card higher
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
||||
import { AnimatePresence, motion } from 'framer-motion'
|
||||
import { processPurposePracticeItems } from '@/data/process-purpose-practice'
|
||||
import { InputArea } from '@/components/practice/InputArea'
|
||||
@@ -219,7 +219,7 @@ export default function ProcessPurposePracticePage() {
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
useLayoutEffect(() => {
|
||||
const deck = deckScrollRef.current
|
||||
if (!deck) return
|
||||
|
||||
@@ -227,7 +227,9 @@ export default function ProcessPurposePracticePage() {
|
||||
const currentCard = deck.querySelector('[data-current-question="true"]') as HTMLElement | null
|
||||
if (!currentCard) return
|
||||
|
||||
const targetTop = Math.max(currentCard.offsetTop - 8, 0)
|
||||
const deckTop = deck.getBoundingClientRect().top
|
||||
const cardTop = currentCard.getBoundingClientRect().top
|
||||
const targetTop = Math.max(deck.scrollTop + cardTop - deckTop - 8, 0)
|
||||
deck.scrollTo({ top: targetTop, behavior: 'smooth' })
|
||||
})
|
||||
}, [progress.currentIndex])
|
||||
|
||||
Reference in New Issue
Block a user