SunUI
创始会员$79 终身更新,1月11日截止领取名额
免费展示滚动

滚动倾斜舞台

3D 舞台:内容先向后倒(rotateX 28deg),滚入视口时慢慢立起来,底下有一抹柔和的黑色落影和一条金色地面细线。

适合使用的场景

  • 在首屏下方展示产品演示或应用窗口
  • 让截图或内嵌演示在滚动时有戏剧性的入场

注意事项

  • 在自定义滚动区域内要传入 scrollContainer,否则进度会跟随窗口
  • 外层使用 overflow-x clip;下方要给落影留出空间

交给你的 agent 安装

一次复制就包含安装命令、使用时机、props 与设计规则。粘贴到 Claude Code、Cursor 或 Codex 即可。

用 CLI 安装

使用 shadcn CLI。源码会复制到你的项目中,每一行都由你掌控。

$ npx shadcn@latest add https://sunui.synvize.com/r/scroll-tilt-stage.json

或手动安装

  1. 1. 安装依赖。
    $ npm install clsx tailwind-merge
  2. 2. 如果还没有,在 lib/utils.ts 添加 cn 辅助函数。没有用 shadcn/ui?再加上 sunui-theme.css 提供颜色变量(做法)。然后复制组件代码。
    scroll-tilt-stage.tsx
    "use client";
    
    import { useEffect, useRef, type ReactNode, type RefObject } from "react";
    
    import { cn } from "@/lib/utils";
    
    export interface ScrollTiltStageProps {
      children: ReactNode;
      /** Color of the plinth's lit top edge (the only accent color); defaults to the brand spot colour, var(--sunui-spot, var(--primary)) */
      accent?: string;
      /** Pass it when used inside a scrollable container; by default it follows the whole window scroll */
      scrollContainer?: RefObject<HTMLElement | null>;
      className?: string;
    }
    
    const clamp = (x: number) => Math.min(1, Math.max(0, x));
    
    /**
     * 3D entrance stage: while still below the viewport it leans back, slowly stands up as it scrolls in, and faces straight on at the middle of the screen.
     * Below it sit a soft black drop shadow and a brushed-metal plinth whose top edge catches the light in the accent colour.
     * The plinth mixes currentColor, so it reads on dark and light sections alike. With reduced motion preferred it simply faces front.
     */
    export function ScrollTiltStage({ children, accent = "var(--sunui-spot, var(--primary))", scrollContainer, className }: ScrollTiltStageProps) {
      const outer = useRef<HTMLDivElement>(null);
      const inner = useRef<HTMLDivElement>(null);
    
      useEffect(() => {
        const o = outer.current;
        const el = inner.current;
        if (!o || !el) return;
        const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
        const root = scrollContainer?.current ?? null;
        const target: HTMLElement | Window = root ?? window;
        let raf = 0;
    
        const apply = () => {
          raf = 0;
          if (mq.matches) {
            el.style.transform = "";
            el.style.opacity = "";
            return;
          }
          const r = o.getBoundingClientRect();
          const box = root?.getBoundingClientRect();
          const top = box ? r.top - box.top : r.top;
          const vh = box ? box.height : window.innerHeight;
          // From the top edge at the bottom of the viewport to 15% of the viewport, 0 → 1 (ease-out quadratic)
          const p = 1 - Math.pow(1 - clamp((vh - top) / (vh * 0.85)), 2);
          el.style.transform = `rotateX(${(1 - p) * 28}deg) scale(${0.88 + 0.12 * p}) translateY(${(1 - p) * 30}px)`;
          el.style.opacity = String(0.6 + 0.4 * p);
        };
        const onScroll = () => {
          if (!raf) raf = requestAnimationFrame(apply);
        };
    
        apply();
        target.addEventListener("scroll", onScroll, { passive: true });
        window.addEventListener("resize", onScroll);
        mq.addEventListener("change", onScroll);
        return () => {
          cancelAnimationFrame(raf);
          target.removeEventListener("scroll", onScroll);
          window.removeEventListener("resize", onScroll);
          mq.removeEventListener("change", onScroll);
        };
      }, [scrollContainer]);
    
      return (
        <div ref={outer} className={cn("relative overflow-x-clip [perspective:1600px]", className)}>
          {/* Drop shadow: solid black, no glow */}
          <div
            aria-hidden
            className="pointer-events-none absolute inset-x-[6%] -bottom-12 h-20"
            style={{ background: "radial-gradient(50% 50% at 50% 50%, rgba(0,0,0,0.55), transparent 100%)" }}
          />
          {/* Plinth: a lit top edge in the accent colour, a pale top face, then a brushed-metal front face with one fixed sheen that darkens downward; faded at both ends.
              Made one notch heavier on 2026-11-25 so it still reads at catalog size */}
          <div
            aria-hidden
            className="pointer-events-none absolute inset-x-[4%] -bottom-10 flex h-[24px] flex-col"
            style={{
              maskImage: "linear-gradient(90deg, transparent, #000 16%, #000 84%, transparent)",
              WebkitMaskImage: "linear-gradient(90deg, transparent, #000 16%, #000 84%, transparent)",
            }}
          >
            <div className="h-[2px] shrink-0" style={{ background: accent, boxShadow: `0 0 0 0.5px color-mix(in srgb, ${accent} 60%, transparent)` }} />
            <div className="h-[4px] shrink-0" style={{ background: "linear-gradient(180deg, color-mix(in srgb, currentColor 48%, transparent), color-mix(in srgb, currentColor 30%, transparent))" }} />
            <div
              className="flex-1"
              style={{
                backgroundImage:
                  "linear-gradient(115deg, transparent 38%, color-mix(in srgb, currentColor 14%, transparent) 50%, transparent 62%), repeating-linear-gradient(90deg, color-mix(in srgb, currentColor 9%, transparent) 0 1px, transparent 1px 3px), linear-gradient(180deg, color-mix(in srgb, currentColor 28%, transparent), color-mix(in srgb, currentColor 6%, transparent))",
                boxShadow: "inset 0 1px 0 rgb(0 0 0 / 0.25)",
              }}
            />
          </div>
          <div ref={inner} className="relative origin-[50%_85%] will-change-transform">
            {children}
          </div>
        </div>
      );
    }