File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments