fix: frame scroll fallback - nearest loaded frame on scroll

This commit is contained in:
2026-07-30 23:09:04 +03:00
parent 08efae2b97
commit 8bf266f2b2
+7 -3
View File
@@ -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)
} }
}) })