fix: frame scroll fallback - nearest loaded frame on scroll
This commit is contained in:
@@ -111,14 +111,18 @@ export default function CloudRevealSection() {
|
|||||||
|
|
||||||
// Scroll → canvas frame çiz
|
// Scroll → canvas frame çiz
|
||||||
useMotionValueEvent(scrollYProgress, 'change', (progress) => {
|
useMotionValueEvent(scrollYProgress, 'change', (progress) => {
|
||||||
const frameIdx = Math.min(
|
const targetIdx = Math.min(
|
||||||
Math.floor(progress * (TOTAL_FRAMES - 1)),
|
Math.floor(progress * (TOTAL_FRAMES - 1)),
|
||||||
TOTAL_FRAMES - 1
|
TOTAL_FRAMES - 1
|
||||||
)
|
)
|
||||||
const img = framesRef.current[frameIdx]
|
// Hedef frame yüklenmemişse geriye doğru ilk yüklü frame'i bul
|
||||||
|
let img: HTMLImageElement | null = null
|
||||||
|
for (let i = targetIdx; i >= 0; i--) {
|
||||||
|
if (framesRef.current[i]) { img = framesRef.current[i]; break }
|
||||||
|
}
|
||||||
const canvas = canvasRef.current
|
const canvas = canvasRef.current
|
||||||
const ctx = canvas?.getContext('2d')
|
const ctx = canvas?.getContext('2d')
|
||||||
if (img && canvas && ctx) {
|
if (img && canvas && ctx && canvas.width > 0) {
|
||||||
ctx.drawImage(img, 0, 0, canvas.width, canvas.height)
|
ctx.drawImage(img, 0, 0, canvas.width, canvas.height)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user