SunUI
創設メンバー$79・永久更新・1月11日まで枠を確保する
無料ショーケーススクロール

スクロールチルトステージ

コンテンツを後ろに倒した状態(rotateX 28deg)から、スクロールで画面に入るにつれて起き上がらせる 3D ステージ。

使いどころ

  • ヒーローの下で製品デモやアプリ画面を見せるとき
  • スクリーンショットや埋め込みデモに、スクロールでドラマチックな登場をさせたいとき

注意点

  • 独自のスクロール領域内では scrollContainer を渡さないと、進捗がウィンドウに連動します
  • ラッパーは overflow-x clip を使うので、落ち影のために下側の余白を残す

エージェントに追加してもらう

インストールコマンド、使いどころ、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. cn ヘルパーがなければ lib/utils.ts に追加します。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>
      );
    }