From 1bfd61f496f050c022968055f3fbb4d41e3525f3 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Mon, 29 Jun 2026 15:28:02 +0330 Subject: [PATCH] zoom with scrol --- src/app/[name]/(Main)/[id]/page.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app/[name]/(Main)/[id]/page.tsx b/src/app/[name]/(Main)/[id]/page.tsx index 1998e2d..0c9225d 100644 --- a/src/app/[name]/(Main)/[id]/page.tsx +++ b/src/app/[name]/(Main)/[id]/page.tsx @@ -88,23 +88,29 @@ function FoodPage({}: Props) { if (!scrollEl || !imageEl) return; const desktopQuery = window.matchMedia("(min-width: 1024px)"); - const PARALLAX_FACTOR = 0.35; + const MAX_SCALE = 1.18; + const MIN_SCALE = 1.0; const applyParallax = () => { if (desktopQuery.matches) { imageEl.style.transform = ""; return; } - imageEl.style.transform = `translate3d(0, ${scrollEl.scrollTop * PARALLAX_FACTOR}px, 0) scale(1.12)`; + const scrollRange = imageEl.parentElement?.offsetHeight ?? 320; + const progress = Math.min(1, Math.max(0, scrollEl.scrollTop / scrollRange)); + const scale = MIN_SCALE + (MAX_SCALE - MIN_SCALE) * progress; + imageEl.style.transform = `scale(${scale})`; }; scrollEl.addEventListener("scroll", applyParallax, { passive: true }); desktopQuery.addEventListener("change", applyParallax); + window.addEventListener("resize", applyParallax); applyParallax(); return () => { scrollEl.removeEventListener("scroll", applyParallax); desktopQuery.removeEventListener("change", applyParallax); + window.removeEventListener("resize", applyParallax); imageEl.style.transform = ""; }; }, [food?.data?.id]); @@ -166,7 +172,7 @@ function FoodPage({}: Props) { {/* eslint-disable-next-line @next/next/no-img-element */} {foodName} {