Skip to content

Commit 490431e

Browse files
committed
fixed abrupt load ini of image
1 parent 2037843 commit 490431e

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/components/EscherBackground.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ export default function EscherBackground() {
1010
const canvasRef = useRef<HTMLCanvasElement>(null);
1111
const containerRef = useRef<HTMLDivElement>(null);
1212
const [isLoaded, setIsLoaded] = useState(false);
13+
const isLoadedRef = useRef(false);
1314

1415
// Compute scroll-based opacity and write directly to canvas.style — no React re-renders.
1516
const applyScrollOpacity = () => {
1617
if (!canvasRef.current) return;
18+
if (!isLoadedRef.current) {
19+
canvasRef.current.style.opacity = "0";
20+
return;
21+
}
1722
const isMobileViewport = window.matchMedia("(max-width: 768px)").matches;
1823
const scrollY = window.scrollY || window.pageYOffset || 0;
1924
const maxDistance = Math.max(window.innerHeight * (isMobileViewport ? 0.62 : 0.9), 1);
@@ -41,6 +46,7 @@ export default function EscherBackground() {
4146
// so all subsequent scroll updates are immediate (no CSS transition lag).
4247
useEffect(() => {
4348
if (!isLoaded || !canvasRef.current) return;
49+
isLoadedRef.current = true;
4450
const c = canvasRef.current;
4551
c.style.transition = 'opacity 1s ease';
4652
applyScrollOpacity(); // sets correct opacity for current scroll position

0 commit comments

Comments
 (0)