# Custom overlay recipes These are ready-to-adapt fragment files for the `custom` overlay type. Each recipe shows the required structure: `...` for the inner HTML, optional `` block, optional `` block. The scaffolder reads these three sections and inlines them into the root composition's `` and `` tags. The inline HTML replaces the `{id}` clip's content. Important rules: - All CSS selectors should be scoped under `#` so they don't bleed into other overlays. - All GSAP tweens go on `tl` (the root timeline already in scope). Time positions must be `>= overlay.start` and `<= overlay.start + overlay.duration` (otherwise the framework hides the element while you're animating it). - Set initial CSS state for any element you'll animate `from` (opacity:0, transform:translate(...)) so the element is invisible until its tween fires. - The root timeline already declares the parent overlay's `opacity: 1 → 0` enter/exit if you don't. To override, write your own `tl.to("#", ...)` at start and end. ## Recipe: terminal demo A code-window animation showing a `print` mistake → corrected version. Used in clip_01_animated for the C-language analogy. ```html
$ print("hello") hello ✕
我以为是蓝色的
$ set_color(blue); print("hello") hello ✓
不是 bug · 是意图遗漏
#o2 .o2-bg { position: absolute; inset: 0; background: rgba(8,12,24,0.94); } #o2 .o2-window { position: absolute; top: 90px; left: 360px; width: 1200px; background: #1e1e1e; border-radius: 18px; border: 2px solid #444; box-shadow: 0 40px 90px rgba(0,0,0,0.7); font-family: "SF Mono", Menlo, Monaco, Consolas, monospace; opacity: 0; transform: translateY(80px); } #o2 .o2-header { background: #2d2d2d; padding: 22px 28px; display: flex; gap: 12px; border-bottom: 1px solid #444; } #o2 .o2-dot { width: 18px; height: 18px; border-radius: 50%; } #o2 .o2-dot.red { background: #ff5f57; } #o2 .o2-dot.yellow { background: #febc2e; } #o2 .o2-dot.green { background: #28c840; } #o2 .o2-body { padding: 50px 60px; font-size: 46px; line-height: 1.6; color: #d4d4d4; min-height: 580px; } #o2 .o2-line { display: block; margin-bottom: 24px; opacity: 0; } #o2 .o2-prompt { color: #6cd9ff; margin-right: 18px; font-weight: 700; } #o2 .o2-fn { color: #c586c0; } #o2 .o2-str { color: #ce9178; } #o2 .o2-arg { color: #9cdcfe; } #o2 .o2-output { font-size: 64px; font-weight: 700; padding-left: 70px; opacity: 0; } #o2 .o2-output.white { color: #ffffff; } #o2 .o2-output.blue { color: #4f9bff; } #o2 .o2-thought { position: relative; background: #fff; color: #1a1a1a; padding: 22px 36px; border-radius: 36px; display: inline-block; font-size: 40px; font-weight: 700; margin: 16px 0 28px 70px; font-family: "PingFang SC", sans-serif; opacity: 0; } #o2 .o2-thought:before { content: ''; position: absolute; top: -22px; left: 80px; border: 14px solid transparent; border-bottom-color: #fff; } #o2 .o2-thought .blue { color: #2476ff; font-weight: 800; } #o2 .o2-x, #o2 .o2-check { font-size: 80px; font-weight: 900; margin-left: 24px; opacity: 0; display: inline-block; vertical-align: middle; } #o2 .o2-x { color: #ff4444; } #o2 .o2-check { color: #28c840; } #o2 .o2-caption { position: absolute; bottom: 80px; left: 0; width: 1920px; text-align: center; font-size: 88px; font-weight: 800; letter-spacing: 4px; color: #ffeb00; text-shadow: 0 6px 22px rgba(0,0,0,0.85); opacity: 0; transform: translateY(40px); } // Replace the literal "42" timestamps with your overlay's `start`. const S = 42; tl.to("#o2", { opacity: 1, duration: 0.5, ease: "power2.out" }, S); tl.to("#o2-window", { y: 0, opacity: 1, duration: 0.7, ease: "power3.out" }, S + 0.3); tl.to("#o2-cmd1", { opacity: 1, duration: 0.4, ease: "power1.out" }, S + 1.2); tl.to("#o2-out1", { opacity: 1, duration: 0.4, ease: "power2.out" }, S + 2.0); tl.to("#o2-thought", { y: 0, opacity: 1, duration: 0.5, ease: "back.out(2)" }, S + 2.8); tl.from("#o2-thought", { scale: 0.85 }, S + 2.8); tl.to("#o2-x", { opacity: 1, duration: 0.4, ease: "back.out(3)" }, S + 3.6); tl.from("#o2-x", { scale: 0.5 }, S + 3.6); tl.to("#o2-cmd2", { opacity: 1, duration: 0.5, ease: "power3.out" }, S + 5.2); tl.from("#o2-cmd2", { x: -40 }, S + 5.2); tl.to("#o2-out2", { opacity: 1, duration: 0.5, ease: "power3.out" }, S + 6.0); tl.from("#o2-out2", { scale: 0.92 }, S + 6.0); tl.to("#o2-check", { opacity: 1, duration: 0.4, ease: "back.out(3)" }, S + 6.6); tl.from("#o2-check", { scale: 0.5 }, S + 6.6); tl.to("#o2-caption", { y: 0, opacity: 1, duration: 0.6, ease: "power2.out" }, S + 7.4); // hold ~10s, then exit tl.to("#o2-window", { y: 30, opacity: 0, duration: 0.6, ease: "power2.in" }, S + 17.0); tl.to("#o2-caption", { y: -20, opacity: 0, duration: 0.6, ease: "power2.in" }, S + 17.0); tl.to("#o2", { opacity: 0, duration: 0.6, ease: "power2.in" }, S + 17.2); ``` ## Recipe: layer-stack diagram Animated abstraction layers (e.g. natural language → code → machine code) stacked vertically with a glowing arrow flowing through them. Useful for explaining hierarchy / pipeline concepts. Skeleton: ```html
自然语言
↓
代码
↓
机器码
#X .ls-bg { position: absolute; inset: 0; background: rgba(8,12,24,0.92); } #X .ls-stack { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); display: flex; flex-direction: column; align-items: center; gap: 30px; } #X .ls-layer { font-size: 90px; font-weight: 800; color: #fff; padding: 30px 60px; border-radius: 12px; border: 3px solid; opacity: 0; transform: translateX(-100px); } #X .ls-layer-1 { border-color: #ffeb00; box-shadow: 0 0 40px rgba(255,235,0,0.4); } #X .ls-layer-2 { border-color: #4f9bff; box-shadow: 0 0 40px rgba(79,155,255,0.3); } #X .ls-layer-3 { border-color: #28c840; box-shadow: 0 0 40px rgba(40,200,64,0.25); } #X .ls-arrow { font-size: 60px; color: rgba(255,255,255,0.5); opacity: 0; } const S = /* overlay start time */; tl.to("#X", { opacity: 1, duration: 0.4 }, S); tl.to("#X #ls-l1", { x: 0, opacity: 1, duration: 0.6, ease: "expo.out" }, S + 0.3); tl.to("#X #ls-a1", { opacity: 1, duration: 0.3 }, S + 0.9); tl.to("#X #ls-l2", { x: 0, opacity: 1, duration: 0.6, ease: "expo.out" }, S + 1.1); tl.to("#X #ls-a2", { opacity: 1, duration: 0.3 }, S + 1.7); tl.to("#X #ls-l3", { x: 0, opacity: 1, duration: 0.6, ease: "expo.out" }, S + 1.9); // exit at S + duration - 0.6 tl.to("#X", { opacity: 0, duration: 0.5 }, S + DURATION - 0.5); ``` Replace `#X` with the actual overlay id (e.g. `#o3`), `S` with start time, and `DURATION` with overlay duration. ## Recipe: before/after split Two side-by-side states with labels — wrong on the left (red), right on the right (green). Skeleton: ```html
改 Python
/* generated.py */
print("white")
✕
改 prompt
"打印蓝色的 hello"
✓
#X .ba-bg { position: absolute; inset: 0; background: rgba(8,12,24,0.94); } #X .ba-half { position: absolute; top: 0; height: 100%; width: 50%; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 80px; opacity: 0; } #X .ba-half.left { left: 0; transform: translateX(-50px); } #X .ba-half.right { right: 0; transform: translateX(50px); } #X .ba-label { font-size: 70px; font-weight: 800; margin-bottom: 30px; } #X .ba-half.left .ba-label { color: #ff4444; } #X .ba-half.right .ba-label { color: #28c840; } #X .ba-content { font-size: 50px; font-family: "SF Mono", Menlo, monospace; color: #d4d4d4; background: #1e1e1e; padding: 30px 50px; border-radius: 12px; max-width: 100%; } #X .ba-mark { font-size: 120px; font-weight: 900; margin-top: 40px; } #X .ba-half.left .ba-mark { color: #ff4444; } #X .ba-half.right .ba-mark { color: #28c840; } const S = /* overlay start */; tl.to("#X", { opacity: 1, duration: 0.4 }, S); tl.to("#X #ba-left", { x: 0, opacity: 1, duration: 0.6, ease: "power3.out" }, S + 0.3); tl.to("#X #ba-right", { x: 0, opacity: 1, duration: 0.6, ease: "power3.out" }, S + 0.6); tl.to("#X", { opacity: 0, duration: 0.5 }, S + DURATION - 0.5); ``` ## Pattern: pulsing emphasis Add a subtle pulse to draw attention to a single element while it's on screen. Use sparingly — once per overlay max. ```js // requires: opacity:1, transform:scale(1) at rest const cycleDur = 1.2; const cycles = Math.ceil(HOLD_DUR / cycleDur); tl.to("#X .pulse-target", { scale: 1.06, duration: cycleDur / 2, ease: "sine.inOut", yoyo: true, repeat: cycles * 2 - 1, }, S + HOLD_START); ``` Never use `repeat: -1`. Always compute a finite repeat count.