Design Vault 用途・構成・配色・本文で検索 /
索引 カテゴリ タグ English
索引に戻る

61 ターンテーブル

動き · 画像と奥行き
ターンテーブル

静止画 — スクリプトが動くと、ここでそのまま動きます

持ち帰る

コピーして貼るか、ファイルに保存して渡す。ネットにつながらない環境には「全部入り」を 1 つ渡せば足りる。

全部入り

motion-turntable-everything.md

このパネルの中身を、URL の先にあるファイルの中身まで含めて 1 つにまとめた Markdown

依頼文

1.4 KB
ターンテーブル — Scroll-driven character turnaround

キャラクターの向き別の絵 4 枚(正面・斜め・横・背面)を、スクロールに合わせて 1 枚ずつ回して見せる。区画の高さは 400vh、中の箱は 100vh の sticky にする。
--p を 0.04〜0.96 の範囲で 4 等分し、それぞれの区間で 1 枚を見せる。区間の境目の前後 7%(1 枚分の長さに対して)では、絵の横幅を `scaleX` で 1 → 0 → 1 と縮めて広げ、幅が 0 になった瞬間に次の絵へ差し替える。縮み方は sin のなめらかさにする。
左に大きな番号(01 / 04)と向きの名前、下に 4 枚の小さな絵を並べて今の 1 枚に下線を引く。足元には楕円の上に 36 本の目盛りを置き、--p に合わせて 1 周回し、手前の目盛りだけを濃くする。
CSS と素の JavaScript だけで実装し、ライブラリは使わない。

外すと崩れる点:
- 絵の差し替えは幅が 0 の瞬間だけ。半分の幅で替えると、別人が回り込んだように見える
- 向き別の絵は同じキャンバス・同じ足元の高さで描く。足元が揃わないと回る間に人物が上下する
- 動きを減らす設定では、4 枚を横に並べて止める

動く実物(1 ファイルで完結する HTML): https://design-vault.pages.dev/designs/motion-turntable/demo.html

ファイル

demo.html

15.5 KB

/designs/motion-turntable/demo.html — 1 ファイルで完結する HTML。CSS と素の JavaScript だけで、外部からは何も読みません。

中身を見る
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>61 ターンテーブル — Scroll-driven character turnaround</title>
<style>
/* dv-motion-base:start */
:root {
  --ground: #FFFFFF;
  --surface: #F3F5F8;
  --ink: #14181F;
  --muted: #5A6472;
  --accent: #1F5FA8;
  --rule: #D8DDE4;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--ground));
  --accent-mid: color-mix(in srgb, var(--accent) 45%, var(--ground));
  --shade: color-mix(in srgb, var(--ink) 14%, transparent);

  --font: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --t-label: 13px;
  --t-body: 16px;
  --t-lead: 20px;
  --t-h2: 32px;
  --t-h1: clamp(40px, 7vw, 72px);

  --s1: 4px;
  --s2: 8px;
  --s3: 16px;
  --s4: 24px;
  --s5: 40px;
  --s6: 64px;
  --s7: 104px;

  --radius: 12px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur: .7s;
  --measure: 1080px;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--t-body);
  line-height: 1.7;
  font-feature-settings: "palt";
  overflow-x: hidden;
}
h1, h2, h3, p, ul, ol, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
.dv-wrap { width: min(100% - 2 * var(--s4), var(--measure)); margin-inline: auto; }
.dv-label {
  min-height: 72vh;
  display: grid;
  align-content: center;
  gap: var(--s3);
  padding-block: var(--s6);
  border-bottom: 1px solid var(--rule);
}
.dv-num { font-family: var(--mono); font-size: var(--t-lead); font-weight: 700; color: var(--accent); letter-spacing: .04em; }
.dv-name { font-size: var(--t-h1); font-weight: 700; line-height: 1.15; letter-spacing: .01em; }
.dv-ai { font-family: var(--mono); font-size: var(--t-lead); color: var(--muted); }
.dv-desc { font-size: var(--t-lead); color: var(--ink); }
.dv-hint { font-size: var(--t-label); color: var(--muted); letter-spacing: .12em; margin-top: var(--s4); }
.dv-stage { padding-block: var(--s7); }
.dv-h2 { font-size: var(--t-h2); font-weight: 700; line-height: 1.3; }
.dv-lead { font-size: var(--t-lead); color: var(--muted); }
.dv-eyebrow { font-family: var(--mono); font-size: var(--t-label); color: var(--accent); letter-spacing: .12em; text-transform: uppercase; }
.dv-card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: var(--s4); }
.dv-ph {
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent-soft), var(--accent-mid) 60%, var(--accent));
  aspect-ratio: 16 / 9;
}
.dv-ph--alt { background: linear-gradient(200deg, var(--surface), var(--accent-soft) 55%, var(--accent-mid)); }
.dv-ph--ink { background: linear-gradient(160deg, var(--ink), color-mix(in srgb, var(--ink) 55%, var(--accent))); }
.dv-end {
  min-height: 60vh;
  display: grid;
  place-items: center;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-family: var(--mono);
  font-size: var(--t-label);
  letter-spacing: .12em;
}
/* dv-motion-base:end */

/* ---- この演出だけの CSS。色は var(--…) か color-mix() のみ ---- */
.f-ink { fill: var(--ink); }
.f-face { fill: var(--surface); }
.f-accent { fill: var(--accent); }
.f-arm { stroke: var(--ink); stroke-width: 30; stroke-linecap: round; fill: none; }
.tt-zone { height: 400vh; }
.tt-box {
  position: sticky; top: 0; height: 100vh; display: grid; align-items: center;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: var(--s4); overflow: clip;
}
.tt-count { font-family: var(--mono); font-weight: 700; line-height: 1; }
.tt-num { font-size: clamp(72px, 16vw, 200px); color: var(--ink); letter-spacing: -.04em; }
.tt-of { font-size: var(--t-lead); color: var(--muted); margin-top: var(--s2); }
.tt-view { font-size: var(--t-h2); font-weight: 700; margin-top: var(--s4); }
.tt-stand { position: relative; height: 82vh; display: grid; justify-items: center; }
.tt-band { position: absolute; inset: 6% 26% 8%; background: var(--accent-soft); border-radius: var(--radius); }
.tt-fig { position: relative; height: 74vh; width: 29.6vh; transform: scaleX(var(--w, 1)); }
.tt-fig svg { width: 100%; height: 100%; display: block; overflow: visible; }
.tt-floor { position: absolute; left: 50%; bottom: 2vh; width: min(36vh, 90%); transform: translateX(-50%); overflow: visible; }
.tt-floor ellipse { fill: none; stroke: var(--rule); stroke-width: 2; }
.tt-floor line { stroke: var(--ink); stroke-width: 2; }
.tt-strip { grid-column: 1 / -1; display: flex; gap: var(--s3); justify-content: center; align-self: end; padding-bottom: var(--s4); }
.tt-thumb { width: 40px; height: 100px; opacity: .3; border-bottom: 4px solid transparent; padding-bottom: var(--s1); }
.tt-thumb svg { width: 100%; height: 100%; display: block; }
.tt-thumb.is-on { opacity: 1; border-color: var(--accent); }
.tt-box { grid-template-rows: 1fr auto; }
@media (max-width: 600px) {
  .tt-box { grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); }
  .tt-stand { height: 64vh; }
  .tt-fig { height: 58vh; width: 23.2vh; }
}
@media (prefers-reduced-motion: reduce) {
  .tt-zone { height: auto; }
  .tt-box { position: static; height: auto; }
  .tt-stand, .tt-count { display: none; }
  .tt-strip { grid-column: 1 / -1; padding-block: var(--s6); gap: var(--s5); }
  .tt-thumb { width: min(18vw, 120px); height: auto; aspect-ratio: 2 / 5; opacity: 1; border-color: transparent; }
  .tt-thumb.is-on { border-color: transparent; }
}
</style>
</head>
<body data-motion-number="61">
<header class="dv-label">
  <div class="dv-wrap">
    <p class="dv-num">61</p>
    <h1 class="dv-name">ターンテーブル</h1>
    <p class="dv-ai">Scroll-driven character turnaround</p>
    <p class="dv-desc">スクロールで人物が回り、正面・斜め・横・背面が入れ替わる</p>
    <p class="dv-hint">SCROLL ↓</p>
  </div>
</header>

<svg width="0" height="0" style="position: absolute" aria-hidden="true">
  <symbol id="fig-front" viewBox="0 0 400 1000">
    <path class="f-ink" d="M128 120 Q120 40 200 34 Q280 40 272 120 L292 430 L108 430 Z"/>
    <rect class="f-ink" x="182" y="210" width="36" height="50"/>
    <ellipse class="f-face" cx="200" cy="150" rx="60" ry="72"/>
    <path class="f-ink" d="M140 118 Q200 60 262 118 L262 96 Q200 40 138 96 Z"/>
    <ellipse class="f-ink" cx="176" cy="158" rx="7" ry="11"/><ellipse class="f-ink" cx="224" cy="158" rx="7" ry="11"/>
    <path class="f-accent" d="M232 70 l40 -26 l6 36 Z M232 70 l-6 -40 l40 16 Z"/>
    <path class="f-ink" d="M128 252 L272 252 L240 520 L160 520 Z"/>
    <path class="f-accent" d="M160 520 L240 520 L296 712 L104 712 Z"/>
    <rect class="f-ink" x="158" y="712" width="30" height="236"/><rect class="f-ink" x="212" y="712" width="30" height="236"/>
    <ellipse class="f-ink" cx="170" cy="956" rx="30" ry="16"/><ellipse class="f-ink" cx="230" cy="956" rx="30" ry="16"/>
    <path class="f-arm" d="M136 262 L104 516"/><path class="f-arm" d="M264 262 L300 496"/>
    <rect class="f-accent" x="282" y="478" width="42" height="58" rx="6"/>
  </symbol>
  <symbol id="fig-34" viewBox="0 0 400 1000">
    <path class="f-ink" d="M136 120 Q132 40 206 34 Q276 42 268 120 L282 430 L116 430 Z"/>
    <rect class="f-ink" x="186" y="210" width="34" height="50"/>
    <ellipse class="f-face" cx="214" cy="150" rx="52" ry="72"/>
    <path class="f-ink" d="M156 116 Q214 62 268 116 L268 94 Q210 42 152 94 Z"/>
    <ellipse class="f-ink" cx="200" cy="158" rx="6" ry="11"/><ellipse class="f-ink" cx="240" cy="158" rx="6" ry="11"/>
    <path class="f-accent" d="M226 70 l36 -24 l6 34 Z M226 70 l-6 -38 l36 14 Z"/>
    <path class="f-ink" d="M140 252 L264 252 L238 520 L166 520 Z"/>
    <path class="f-accent" d="M166 520 L238 520 L286 712 L118 712 Z"/>
    <rect class="f-ink" x="166" y="712" width="28" height="236"/><rect class="f-ink" x="214" y="712" width="28" height="236"/>
    <ellipse class="f-ink" cx="184" cy="956" rx="28" ry="16"/><ellipse class="f-ink" cx="236" cy="956" rx="30" ry="16"/>
    <path class="f-arm" d="M146 262 L122 512"/><path class="f-arm" d="M256 262 L284 496"/>
    <rect class="f-accent" x="266" y="478" width="38" height="58" rx="6"/>
  </symbol>
  <symbol id="fig-side" viewBox="0 0 400 1000">
    <path class="f-ink" d="M150 120 Q150 40 214 36 Q262 44 258 120 L246 420 L150 420 Z"/>
    <path class="f-face" d="M210 92 Q262 96 266 150 L276 170 L264 176 Q262 214 222 222 L206 222 Z"/>
    <ellipse class="f-ink" cx="244" cy="156" rx="5" ry="10"/>
    <path class="f-accent" d="M196 66 l-34 -30 l-6 34 Z"/>
    <rect class="f-ink" x="194" y="214" width="30" height="46"/>
    <path class="f-ink" d="M168 252 L246 252 L236 520 L172 520 Z"/>
    <path class="f-accent" d="M172 520 L236 520 L266 712 L142 712 Z"/>
    <rect class="f-ink" x="186" y="712" width="32" height="236"/>
    <path class="f-ink" d="M186 948 L248 948 Q252 970 230 970 L186 970 Z"/>
    <path class="f-arm" d="M208 266 L222 500"/>
    <rect class="f-accent" x="204" y="484" width="44" height="56" rx="6"/>
  </symbol>
  <symbol id="fig-back" viewBox="0 0 400 1000">
    <path class="f-ink" d="M128 120 Q120 40 200 34 Q280 40 272 120 L292 430 L108 430 Z"/>
    <rect class="f-ink" x="182" y="210" width="36" height="50"/>
    <path class="f-accent" d="M232 70 l40 -26 l6 36 Z M232 70 l-6 -40 l40 16 Z"/>
    <path class="f-ink" d="M128 252 L272 252 L240 520 L160 520 Z"/>
    <path class="f-accent" d="M160 520 L240 520 L296 712 L104 712 Z"/>
    <rect class="f-ink" x="158" y="712" width="30" height="236"/><rect class="f-ink" x="212" y="712" width="30" height="236"/>
    <ellipse class="f-ink" cx="170" cy="956" rx="30" ry="16"/><ellipse class="f-ink" cx="230" cy="956" rx="30" ry="16"/>
    <path class="f-arm" d="M136 262 L104 516"/><path class="f-arm" d="M264 262 L300 496"/>
  </symbol>
</svg>
<main class="dv-stage">
  <div class="dv-wrap">
    <section class="tt-zone" data-progress="pin">
      <div class="tt-box">
        <div class="tt-count">
          <p class="tt-num"><span class="tt-i">01</span></p>
          <p class="tt-of">/ 04</p>
          <p class="tt-view">正面</p>
        </div>
        <div class="tt-stand">
          <div class="tt-band"></div>
          <div class="tt-fig"><svg viewBox="0 0 400 1000" role="img" aria-label="代役の人物"><use href="#fig-front"/></svg></div>
          <svg class="tt-floor" viewBox="-180 -40 360 80" aria-hidden="true"><ellipse rx="170" ry="28"/><g class="tt-ticks"></g></svg>
        </div>
        <div class="tt-strip">
        <figure class="tt-thumb" aria-label="正面"><svg viewBox="0 0 400 1000"><use href="#fig-front"/></svg></figure>
        <figure class="tt-thumb" aria-label="斜め"><svg viewBox="0 0 400 1000"><use href="#fig-34"/></svg></figure>
        <figure class="tt-thumb" aria-label="横"><svg viewBox="0 0 400 1000"><use href="#fig-side"/></svg></figure>
        <figure class="tt-thumb" aria-label="背面"><svg viewBox="0 0 400 1000"><use href="#fig-back"/></svg></figure>
        </div>
      </div>
    </section>
  </div>
</main>

<footer class="dv-end">END — 61 ターンテーブル</footer>

<script>
/* dv-motion-helpers:start */
const dvReduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
document.documentElement.classList.add('js');

/**
 * 画面に入った要素へ .is-in を付ける。
 * data-reveal="repeat" の要素は画面を出たら外す(何度でも再生)。
 */
function dvReveal(selector = '[data-reveal]', { threshold = 0.2, rootMargin = '0px 0px -8% 0px' } = {}) {
  const els = [...document.querySelectorAll(selector)];
  if (dvReduce || !('IntersectionObserver' in window)) {
    els.forEach((el) => el.classList.add('is-in'));
    return;
  }
  const io = new IntersectionObserver((entries) => {
    for (const e of entries) {
      if (e.isIntersecting) {
        e.target.classList.add('is-in');
        if (e.target.dataset.reveal !== 'repeat') io.unobserve(e.target);
      } else if (e.target.dataset.reveal === 'repeat') {
        e.target.classList.remove('is-in');
      }
    }
  }, { threshold, rootMargin });
  els.forEach((el) => io.observe(el));
}

/**
 * スクロール量を 0〜1 にして、各 [data-progress] 要素の CSS 変数 --p に書く。
 *   data-progress="through" : 要素の上端が画面の下端に来たとき 0、下端が画面の上端を抜けたとき 1
 *   data-progress="pin"     : 要素の上端が画面の上端に来たとき 0、下端が画面の下端に来たとき 1
 *                             (中に position: sticky の箱を持つ、背の高い区画用)
 *   data-progress="page"    : ページ全体のスクロール量
 * onUpdate(el, p) を渡すと、値が変わるたびに呼ばれる。
 */
function dvProgress(onUpdate) {
  const els = [...document.querySelectorAll('[data-progress]')];
  const clamp = (n) => Math.min(1, Math.max(0, n));
  let queued = false;
  const measure = () => {
    queued = false;
    const vh = window.innerHeight;
    for (const el of els) {
      const r = el.getBoundingClientRect();
      let p;
      if (el.dataset.progress === 'pin') p = r.height > vh ? -r.top / (r.height - vh) : 0;
      else if (el.dataset.progress === 'page') {
        const max = document.documentElement.scrollHeight - vh;
        p = max > 0 ? window.scrollY / max : 0;
      } else p = (vh - r.top) / (vh + r.height);
      p = clamp(p);
      el.style.setProperty('--p', p.toFixed(4));
      if (onUpdate) onUpdate(el, p);
    }
  };
  const request = () => {
    if (!queued) { queued = true; requestAnimationFrame(measure); }
  };
  addEventListener('scroll', request, { passive: true });
  addEventListener('resize', request);
  measure();
}
/* dv-motion-helpers:end */

/* ---- この演出だけの JS ---- */
// 向き別の絵を、進み p に合わせて 1 枚ずつ回して見せる。境目では幅を 1 → 0 → 1 にし、幅 0 の瞬間に絵を差し替える。
const VIEWS = [['front', '正面'], ['34', '斜め'], ['side', '横'], ['back', '背面']];
const SPAN = [0.04, 0.96], TURN = 0.14;
function turnAt(p, n) {
  const pos = Math.min(n - 1e-9, Math.max(0, ((p - SPAN[0]) / (SPAN[1] - SPAN[0])) * n));
  const i = Math.floor(pos), f = pos - i, half = TURN / 2;
  let w = 1;
  if (i > 0 && f < half) w = f / half;
  else if (i < n - 1 && f > 1 - half) w = (1 - f) / half;
  return { i, w: Math.sin((w * Math.PI) / 2) };
}
const zone = document.querySelector('.tt-zone');
const fig = zone.querySelector('.tt-fig'), use = fig.querySelector('use');
const ticks = zone.querySelector('.tt-ticks');
const NS = 'http://www.w3.org/2000/svg';
const marks = Array.from({ length: 36 }, (_, k) => {
  const l = document.createElementNS(NS, 'line');
  ticks.appendChild(l);
  return l;
});
let shown = -1;
dvProgress((el, p) => {
  const { i, w } = turnAt(dvReduce ? 1 : p, VIEWS.length);
  fig.style.setProperty('--w', w.toFixed(4));
  if (i !== shown) {
    shown = i;
    use.setAttribute('href', `#fig-${VIEWS[i][0]}`);
    zone.querySelector('.tt-i').textContent = String(i + 1).padStart(2, '0');
    zone.querySelector('.tt-view').textContent = VIEWS[i][1];
    zone.querySelectorAll('.tt-thumb').forEach((t, k) => t.classList.toggle('is-on', k === i));
  }
  // 足元の目盛りは p に合わせて 1 周する。手前の目盛りだけを濃くする。
  marks.forEach((l, k) => {
    const a = ((k * 10 + p * 360) * Math.PI) / 180, x = Math.cos(a) * 170, y = Math.sin(a) * 28;
    l.setAttribute('x1', x.toFixed(1)); l.setAttribute('x2', x.toFixed(1));
    l.setAttribute('y1', y.toFixed(1)); l.setAttribute('y2', (y + (k % 3 ? 7 : 13)).toFixed(1));
    l.style.opacity = Math.sin(a) > 0 ? 0.85 : 0.2;
  });
});
</script>
</body>
</html>

/ai/assets/motion-turntable.json