3Dカルーセル

パネルを円柱状に配置し前後ボタンと自動送りで回転する3Dカルーセル。ギャラリーやプロダクト紹介の回遊導線に使えます。

#css#javascript#3d#carousel

ライブデモ

使用例(お題: アイドルグループ Sakura)

この技法を「アイドルグループ Sakura」というテーマのダミーサイトで実際に使った例です。

HTML
<!-- Sakura:ライブ/MVを円柱状に並べた3Dカルーセル -->
<section class="sk-mv" aria-label="Sakura ミュージックビデオ一覧">
  <header class="sk-mv__head">
    <span class="sk-mv__logo">🌸 Sakura</span>
    <h2 class="sk-mv__title">MUSIC VIDEO</h2>
  </header>

  <div class="sk-mv__stage">
    <!-- パネルをJSが円柱状に配置・自動送り -->
    <div class="sk-ring" id="skRing">
      <figure class="sk-panel"><span class="sk-panel__no">01</span><span class="sk-panel__name">花びらラプソディ</span></figure>
      <figure class="sk-panel"><span class="sk-panel__no">02</span><span class="sk-panel__name">春一番センセーション</span></figure>
      <figure class="sk-panel"><span class="sk-panel__no">03</span><span class="sk-panel__name">満開ストーリー</span></figure>
      <figure class="sk-panel"><span class="sk-panel__no">04</span><span class="sk-panel__name">夜桜ランデブー</span></figure>
      <figure class="sk-panel"><span class="sk-panel__no">05</span><span class="sk-panel__name">きみいろパレット</span></figure>
      <figure class="sk-panel"><span class="sk-panel__no">06</span><span class="sk-panel__name">ハナミドキ</span></figure>
    </div>
  </div>

  <div class="sk-mv__nav">
    <button class="sk-mv__btn" id="skPrev" type="button" aria-label="前へ">‹</button>
    <span class="sk-mv__status" id="skStatus" aria-live="polite">01 / 06</span>
    <button class="sk-mv__btn" id="skNext" type="button" aria-label="次へ">›</button>
  </div>
</section>
CSS
/* Sakura:桜ピンクの3D MVカルーセル */
:root {
  --pink: #ffd1e0;
  --pink-deep: #ff8fb3;
  --gray: #f1eef0;
  --pw: 170px;   /* パネル幅 */
  --ph: 110px;   /* パネル高 */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 400px;
  display: flex;
  flex-direction: column;
  font-family: "Hiragino Kaku Gothic ProN", "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(170deg, #fff 0%, var(--pink) 70%, #ffc0d8 100%);
  color: #7a3553;
  overflow: hidden;
}

.sk-mv__head { text-align: center; padding: 16px 0 4px; }
.sk-mv__logo { font-size: 13px; font-weight: 800; letter-spacing: 0.1em; color: #c94d7d; }
.sk-mv__title { margin: 2px 0 0; font-size: 18px; letter-spacing: 0.22em; color: #b07089; }

/* 3Dステージ:perspective が立体の肝 */
.sk-mv__stage {
  flex: 1;
  display: grid;
  place-items: center;
  perspective: 900px;
}

.sk-ring {
  position: relative;
  width: var(--pw);
  height: var(--ph);
  transform-style: preserve-3d; /* パネルを3D空間へ */
  transition: transform 0.6s cubic-bezier(.2,.8,.25,1);
}

.sk-panel {
  position: absolute;
  width: var(--pw);
  height: var(--ph);
  margin: 0;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px;
  color: #fff;
  border: 2px solid rgba(255,255,255,.7);
  background: linear-gradient(160deg, rgba(255,156,192,.95), rgba(255,138,177,.95));
  box-shadow: 0 14px 30px rgba(214,94,140,.35);
  backface-visibility: hidden;
}
/* MVサムネ風の写真を半透明に重ねる */
.sk-panel::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: 12px;
  background: url("https://picsum.photos/200/140?random=61") center/cover no-repeat;
  opacity: .55;
  mix-blend-mode: luminosity;
}
.sk-panel__no {
  position: relative;
  font-size: 11px; letter-spacing: 0.18em; font-weight: 800;
  opacity: .9;
}
.sk-panel__name {
  position: relative;
  font-size: 13px; font-weight: 700; margin-top: 2px;
  text-shadow: 0 2px 6px rgba(140,40,80,.6);
}

.sk-mv__nav {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 12px 0 16px;
}
.sk-mv__btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; cursor: pointer;
  font-size: 20px; color: #fff;
  background: linear-gradient(135deg, #ff9cc0, var(--pink-deep));
  box-shadow: 0 6px 14px rgba(255,122,168,.45);
  transition: transform 0.2s ease;
}
.sk-mv__btn:hover { transform: scale(1.08); }
.sk-mv__btn:active { transform: scale(0.95); }
.sk-mv__status { font-size: 12px; font-weight: 700; color: #c94d7d; letter-spacing: 0.1em; }

@media (prefers-reduced-motion: reduce) {
  .sk-ring { transition: none; }
}
JavaScript
// Sakura 3D MVカルーセル:パネルを円柱状に配置し、前後ボタン+自動送りで回転
(() => {
  const ring = document.getElementById("skRing");
  const prev = document.getElementById("skPrev");
  const next = document.getElementById("skNext");
  const status = document.getElementById("skStatus");
  if (!ring) return; // null安全

  const panels = Array.from(ring.querySelectorAll(".sk-panel"));
  const count = panels.length;
  if (!count) return;

  const angle = 360 / count;           // パネル間の角度
  const radius = 200;                  // 円柱の半径
  let index = 0;
  const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;

  // 各パネルを円周上に配置
  panels.forEach((p, i) => {
    p.style.transform = `rotateY(${i * angle}deg) translateZ(${radius}px)`;
  });

  // 現在位置までリングを回す
  const render = () => {
    ring.style.transform = `translateZ(-${radius}px) rotateY(${-index * angle}deg)`;
    const n = ((index % count) + count) % count; // 正の剰余
    if (status) {
      status.textContent =
        String(n + 1).padStart(2, "0") + " / " + String(count).padStart(2, "0");
    }
  };

  const go = (dir) => { index += dir; render(); };
  prev?.addEventListener("click", () => go(-1));
  next?.addEventListener("click", () => go(1));

  render();

  // 自動送り(ホバー中は停止)
  let timer = null;
  const start = () => { if (!reduce && !timer) timer = setInterval(() => go(1), 2600); };
  const stop = () => { if (timer) { clearInterval(timer); timer = null; } };
  ring.parentElement?.addEventListener("pointerenter", stop);
  ring.parentElement?.addEventListener("pointerleave", start);
  start();
})();

コード

HTML
<div class="carousel" aria-label="3Dカルーセルのデモ">
  <div class="carousel__stage">
    <!-- パネルはJSが円柱状に配置 -->
    <div class="carousel__ring" id="ring">
      <figure class="panel"><span class="panel__idx">01</span><span class="panel__txt">OCEAN</span></figure>
      <figure class="panel"><span class="panel__idx">02</span><span class="panel__txt">FOREST</span></figure>
      <figure class="panel"><span class="panel__idx">03</span><span class="panel__txt">SUNSET</span></figure>
      <figure class="panel"><span class="panel__idx">04</span><span class="panel__txt">AURORA</span></figure>
      <figure class="panel"><span class="panel__idx">05</span><span class="panel__txt">MAGMA</span></figure>
      <figure class="panel"><span class="panel__idx">06</span><span class="panel__txt">FROST</span></figure>
    </div>
  </div>
  <div class="carousel__nav">
    <button class="carousel__btn" id="prev" type="button" aria-label="前へ">‹</button>
    <button class="carousel__btn" id="next" type="button" aria-label="次へ">›</button>
  </div>
</div>
CSS
/* ===== 3Dカルーセル ===== */
* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 360px;
  display: grid;
  place-items: center;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(165deg, #141625 0%, #060611 100%);
  overflow: hidden;
}

.carousel { display: grid; place-items: center; gap: 14px; }

.carousel__stage {
  width: 200px;
  height: 200px;
  perspective: 1000px; /* 奥行きの強さ */
}

.carousel__ring {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  /* JSが --angle を更新して回転 */
  transform: translateZ(-280px) rotateY(var(--angle, 0deg));
  transition: transform .7s cubic-bezier(.2,.8,.25,1);
}

.panel {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-content: center;
  text-align: center;
  border-radius: 14px;
  color: #fff;
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
  backface-visibility: hidden;
  /* JS が各パネルに --rot を設定して円周に並べる */
  transform: rotateY(var(--rot, 0deg)) translateZ(280px);
}
/* 6面それぞれ違うグラデ */
.panel:nth-child(1) { background: linear-gradient(135deg, #2193b0, #6dd5ed); }
.panel:nth-child(2) { background: linear-gradient(135deg, #11998e, #38ef7d); }
.panel:nth-child(3) { background: linear-gradient(135deg, #f7971e, #ff5f6d); }
.panel:nth-child(4) { background: linear-gradient(135deg, #654ea3, #43cea2); }
.panel:nth-child(5) { background: linear-gradient(135deg, #c31432, #ff5e62); }
.panel:nth-child(6) { background: linear-gradient(135deg, #2c3e50, #4ca1af); }

.panel__idx {
  font-size: 13px; letter-spacing: .3em; opacity: .75;
}
.panel__txt {
  font-size: 24px; font-weight: 800; letter-spacing: .12em;
  margin-top: 4px;
  text-shadow: 0 4px 14px rgba(0,0,0,.4);
}

.carousel__nav { display: flex; gap: 16px; }
.carousel__btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.06);
  color: #fff;
  font-size: 22px; line-height: 1;
  cursor: pointer;
  transition: background .2s, transform .15s;
  display: grid; place-items: center;
}
.carousel__btn:hover { background: rgba(255,255,255,.18); }
.carousel__btn:active { transform: scale(.92); }
.carousel__btn:focus-visible { outline: 2px solid #6dd5ed; outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .carousel__ring { transition: none; }
}
JavaScript
// 3Dカルーセル: パネルを円柱状に配置し、前後ボタン+自動送りで回転
(() => {
  const ring = document.getElementById('ring');
  const prev = document.getElementById('prev');
  const next = document.getElementById('next');
  if (!ring || !prev || !next) return; // null安全

  const panels = Array.from(ring.querySelectorAll('.panel'));
  const count = panels.length;
  if (count === 0) return;

  const step = 360 / count; // パネル1枚あたりの角度
  let index = 0;

  // 各パネルを円周上に配置
  panels.forEach((p, i) => {
    p.style.setProperty('--rot', (step * i) + 'deg');
  });

  const update = () => {
    ring.style.setProperty('--angle', (-step * index) + 'deg');
  };

  const go = (dir) => { index += dir; update(); };

  prev.addEventListener('click', () => go(-1));
  next.addEventListener('click', () => go(1));

  // 自動送り(操作後は一時停止)
  const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  let timer = null;
  const start = () => {
    if (reduce) return;
    stop();
    timer = setInterval(() => go(1), 2600);
  };
  const stop = () => { if (timer) { clearInterval(timer); timer = null; } };

  [prev, next].forEach((b) => b.addEventListener('click', () => { stop(); start(); }));

  update();
  start();
})();

🤖 AIエージェント用プロンプト

このままコピーしてAIに貼り付け「追加する場所」だけ書き換えればOK
あなたは熟練のフロントエンドエンジニアです。私のWebサイトに「3Dカルーセル」の効果を追加してください。

# 追加してほしい効果
3Dカルーセル(3D & パースペクティブ)
パネルを円柱状に配置し前後ボタンと自動送りで回転する3Dカルーセル。ギャラリーやプロダクト紹介の回遊導線に使えます。

# 追加する場所
👉【ここに対象箇所を記入:例「トップのヒーローセクション」「お問い合わせボタン」「記事カードの一覧」など】

# 参考実装(この見た目・挙動を再現してください)
【HTML】
<div class="carousel" aria-label="3Dカルーセルのデモ">
  <div class="carousel__stage">
    <!-- パネルはJSが円柱状に配置 -->
    <div class="carousel__ring" id="ring">
      <figure class="panel"><span class="panel__idx">01</span><span class="panel__txt">OCEAN</span></figure>
      <figure class="panel"><span class="panel__idx">02</span><span class="panel__txt">FOREST</span></figure>
      <figure class="panel"><span class="panel__idx">03</span><span class="panel__txt">SUNSET</span></figure>
      <figure class="panel"><span class="panel__idx">04</span><span class="panel__txt">AURORA</span></figure>
      <figure class="panel"><span class="panel__idx">05</span><span class="panel__txt">MAGMA</span></figure>
      <figure class="panel"><span class="panel__idx">06</span><span class="panel__txt">FROST</span></figure>
    </div>
  </div>
  <div class="carousel__nav">
    <button class="carousel__btn" id="prev" type="button" aria-label="前へ">‹</button>
    <button class="carousel__btn" id="next" type="button" aria-label="次へ">›</button>
  </div>
</div>

【CSS】
/* ===== 3Dカルーセル ===== */
* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 360px;
  display: grid;
  place-items: center;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(165deg, #141625 0%, #060611 100%);
  overflow: hidden;
}

.carousel { display: grid; place-items: center; gap: 14px; }

.carousel__stage {
  width: 200px;
  height: 200px;
  perspective: 1000px; /* 奥行きの強さ */
}

.carousel__ring {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  /* JSが --angle を更新して回転 */
  transform: translateZ(-280px) rotateY(var(--angle, 0deg));
  transition: transform .7s cubic-bezier(.2,.8,.25,1);
}

.panel {
  position: absolute;
  inset: 0;
  margin: 0;
  display: grid;
  place-content: center;
  text-align: center;
  border-radius: 14px;
  color: #fff;
  border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
  backface-visibility: hidden;
  /* JS が各パネルに --rot を設定して円周に並べる */
  transform: rotateY(var(--rot, 0deg)) translateZ(280px);
}
/* 6面それぞれ違うグラデ */
.panel:nth-child(1) { background: linear-gradient(135deg, #2193b0, #6dd5ed); }
.panel:nth-child(2) { background: linear-gradient(135deg, #11998e, #38ef7d); }
.panel:nth-child(3) { background: linear-gradient(135deg, #f7971e, #ff5f6d); }
.panel:nth-child(4) { background: linear-gradient(135deg, #654ea3, #43cea2); }
.panel:nth-child(5) { background: linear-gradient(135deg, #c31432, #ff5e62); }
.panel:nth-child(6) { background: linear-gradient(135deg, #2c3e50, #4ca1af); }

.panel__idx {
  font-size: 13px; letter-spacing: .3em; opacity: .75;
}
.panel__txt {
  font-size: 24px; font-weight: 800; letter-spacing: .12em;
  margin-top: 4px;
  text-shadow: 0 4px 14px rgba(0,0,0,.4);
}

.carousel__nav { display: flex; gap: 16px; }
.carousel__btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.06);
  color: #fff;
  font-size: 22px; line-height: 1;
  cursor: pointer;
  transition: background .2s, transform .15s;
  display: grid; place-items: center;
}
.carousel__btn:hover { background: rgba(255,255,255,.18); }
.carousel__btn:active { transform: scale(.92); }
.carousel__btn:focus-visible { outline: 2px solid #6dd5ed; outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .carousel__ring { transition: none; }
}

【JavaScript】
// 3Dカルーセル: パネルを円柱状に配置し、前後ボタン+自動送りで回転
(() => {
  const ring = document.getElementById('ring');
  const prev = document.getElementById('prev');
  const next = document.getElementById('next');
  if (!ring || !prev || !next) return; // null安全

  const panels = Array.from(ring.querySelectorAll('.panel'));
  const count = panels.length;
  if (count === 0) return;

  const step = 360 / count; // パネル1枚あたりの角度
  let index = 0;

  // 各パネルを円周上に配置
  panels.forEach((p, i) => {
    p.style.setProperty('--rot', (step * i) + 'deg');
  });

  const update = () => {
    ring.style.setProperty('--angle', (-step * index) + 'deg');
  };

  const go = (dir) => { index += dir; update(); };

  prev.addEventListener('click', () => go(-1));
  next.addEventListener('click', () => go(1));

  // 自動送り(操作後は一時停止)
  const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  let timer = null;
  const start = () => {
    if (reduce) return;
    stop();
    timer = setInterval(() => go(1), 2600);
  };
  const stop = () => { if (timer) { clearInterval(timer); timer = null; } };

  [prev, next].forEach((b) => b.addEventListener('click', () => { stop(); start(); }));

  update();
  start();
})();

# 外部ライブラリ
なし(追加ライブラリ不要)

# 守ってほしいこと
- 既存のHTML構造・レイアウト・デザインを壊さないこと。必要に応じてクラス名・色・サイズを私のサイトに合わせて調整してよい。
- クラス名やidが既存と衝突しないよう、必要なら接頭辞で名前空間を分けること。
- レスポンシブ対応と prefers-reduced-motion への配慮を入れること。
- 私のサイトのフレームワーク(React / Vue / 素のHTML など)に合わせて実装すること。不明な場合は素のHTML/CSS/JSで提示し、組み込み手順も説明すること。
- 変更後の確認手順も簡潔に教えてください。