From 8bf266f2b297a5fd97161111a9df8c457be9cdf9 Mon Sep 17 00:00:00 2001 From: Mustafa Date: Thu, 30 Jul 2026 23:09:04 +0300 Subject: [PATCH] fix: frame scroll fallback - nearest loaded frame on scroll --- components/sections/CloudRevealSection.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/sections/CloudRevealSection.tsx b/components/sections/CloudRevealSection.tsx index 476b49c..87e9041 100644 --- a/components/sections/CloudRevealSection.tsx +++ b/components/sections/CloudRevealSection.tsx @@ -111,14 +111,18 @@ export default function CloudRevealSection() { // Scroll → canvas frame çiz useMotionValueEvent(scrollYProgress, 'change', (progress) => { - const frameIdx = Math.min( + const targetIdx = Math.min( Math.floor(progress * (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 ctx = canvas?.getContext('2d') - if (img && canvas && ctx) { + if (img && canvas && ctx && canvas.width > 0) { ctx.drawImage(img, 0, 0, canvas.width, canvas.height) } })