Quellcode durchsuchen

perf: stop cards going blank when scrolled back into view in Chrome

Chrome kept about 95 megapixels of GPU layers on the home page, and
when it ran short it dropped the tiles of cards off screen: scrolled
back, a card showed blank until it was painted again.

- The rim glint filled forwards, so Chrome treated it as a running
  animation forever and kept each band, 2.2 cards wide, as a layer of
  its own. It now fills backwards only and lets go once it has played.
- The project screenshots carried a perspective transform at rest,
  which held each one in a 3D layer. The lean is now applied only
  under the cursor, where --tx/--ty are non-zero anyway.

Layer area at 1440x900 goes from 95 to about 56 megapixels (161 to
112 layers), with no visible change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ericwu vor 1 Monat
Ursprung
Commit
2275b3d02b
2 geänderte Dateien mit 9 neuen und 3 gelöschten Zeilen
  1. 3 1
      components/cards/project.tsx
  2. 6 2
      styles/globals.css

+ 3 - 1
components/cards/project.tsx

@@ -66,9 +66,11 @@ export function ProjectCard({
   return (
     <div className={cn("group relative h-full w-full overflow-hidden", l.bg)}>
       <div className={cn("absolute rounded-full bg-stage-blob", l.blob)} />
+      {/* The lean is 3D only under the cursor (--tx/--ty are 0 elsewhere): a
+          perspective at rest held the screenshot in a GPU layer of its own. */}
       <div
         className={cn(
-          "absolute rounded-2xl -rotate-[30deg] transition-[rotate,scale,translate] duration-700 ease-[cubic-bezier(.2,.9,.25,1)] [transform:perspective(1100px)_rotateX(calc(var(--ty,0)*-6deg))_rotateY(calc(var(--tx,0)*8deg))] group-hover:scale-[1.03] group-hover:-rotate-[27deg]",
+          "absolute rounded-2xl -rotate-[30deg] transition-[rotate,scale,translate] duration-700 ease-[cubic-bezier(.2,.9,.25,1)] group-hover:scale-[1.03] group-hover:-rotate-[27deg] group-hover:[transform:perspective(1100px)_rotateX(calc(var(--ty,0)*-6deg))_rotateY(calc(var(--tx,0)*8deg))]",
           l.shot,
         )}
         data-lens

+ 6 - 2
styles/globals.css

@@ -634,7 +634,11 @@ html:lang(zh) :is(.font-display, .title, .notion-h, .notion-title) {
     animation-delay: calc(var(--i, 0) * 45ms);
   }
 
-  /* The glint: a band of light swept across the rim once, on the compositor. */
+  /* The glint: a band of light swept across the rim once, on the compositor.
+     It fills backwards only: an animation that fills forwards never ends for
+     Chrome, which kept each band (2.2 cards wide) as a GPU layer for good, and
+     with fifteen of them, cards scrolled back into view came up blank. Done,
+     the band falls back to -100%, as far off the card as +100%. */
   .card[data-enter] .card-rim::after {
     content: "";
     position: absolute;
@@ -646,7 +650,7 @@ html:lang(zh) :is(.font-display, .title, .notion-h, .notion-title) {
       transparent 58%
     );
     translate: -100% 0;
-    animation: glint 1.4s cubic-bezier(0.3, 0.6, 0.2, 1) both;
+    animation: glint 1.4s cubic-bezier(0.3, 0.6, 0.2, 1) backwards;
     animation-delay: calc(var(--i, 0) * 45ms + 0.25s);
   }