全部效果自动播放与循环

翻页时钟

Flip Clock

数字卡片的上半页向下翻转,露出下一位时间。

播放或暂停演示

适用场景

给短时倒计时或装饰时钟增加机械翻页感。 适合按固定间隔更新、字位较少的时间显示,每块数字卡可预留等宽位置。

应用示例

线上电影放映页显示开场前剩余的分秒。每过一秒,变化的数字上半页向下翻转,露出下一位时间,「距开场」的说明一直固定。

AI 提示词

给【目标时间显示】做翻页时钟。把每位数字裁成上下两半,旧数字的上半页绕下边沿翻转。翻页时更新实际的时间值,保留可读文字,减少动态时显示固定数字。

示例代码

保存为 HTML 文件后,用浏览器打开即可运行。代码与页面里的演示一致。

查看 HTML
<!doctype html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>翻页时钟</title>
  <style>
    :root {
      color-scheme: dark;
      --demo-bg: #171629;
      --demo-ink: #f8f5ff;
      --demo-accent: #b9a6ff;
      --demo-muted: #bfbbd3;
      font-family: system-ui, sans-serif;
      color: var(--demo-ink);
      background: var(--demo-bg);
    }

    *, *::before, *::after { box-sizing: border-box; }
    body { margin: 0; min-width: 0; }
    button, input { font: inherit; }

    .demo {
      display: grid;
      place-items: center;
      align-content: center;
      min-height: 100vh;
      padding: 14px;
      overflow: hidden;
      background: radial-gradient(ellipse at 50% 24%, #28233f, var(--demo-bg) 78%);
    }

    .demo-button {
      border: 1px solid #ffffff3d;
      border-radius: 7px;
      background: #ffffff12;
      color: var(--demo-ink);
      padding: 6px 11px;
      font-size: 12px;
      cursor: pointer;
    }

    :focus-visible {
      outline: 2px solid var(--demo-accent);
      outline-offset: 3px;
    }

    .flap-time { display: flex; align-items: center; gap: 5px; color: #fff4db; font: 750 30px/1 ui-monospace, monospace; }
    .flap-time > b span { padding-left: 4px; color: #c6889b; }
    .flap-digit {
      position: relative; display: grid; place-items: center; width: 73px; height: 60px;
      overflow: hidden; perspective: 180px; border-radius: 8px; background: #45334e;
    }
    .flap-digit::after { content: ''; position: absolute; inset: 50% 0 auto; height: 1px; background: #171326; }
    .flap-next, .flap-panel { position: absolute; inset: 0; display: grid; place-items: center; background: #45334e; }
    .flap-next { animation: clock-next 4.2s steps(1) infinite; }
    .flap-panel { clip-path: inset(0 0 50%); background: #594364; animation: clock-flap 4.2s ease-in-out infinite; }
    @keyframes clock-next { 0%, 25%, 92%, 100% { visibility: hidden; } 26%, 91% { visibility: visible; } }
    @keyframes clock-flap { 0%, 25% { transform: rotateX(0); } 42%, 86% { transform: rotateX(-95deg); } 95%, 100% { transform: rotateX(0); } }

    .motion-example { display: grid; justify-items: center; width: 100%; gap: 10px; }
    .motion-specimen {
      display: grid;
      place-items: center;
      width: min(100%, 295px);
      height: 108px;
      position: relative;
      isolation: isolate;
    }
    .motion-example [data-motion] { animation-play-state: paused; }
    .motion-example[data-playing] [data-motion] { animation-play-state: running; }
    @media (prefers-reduced-motion: reduce) {
      .motion-example [data-motion] { animation: none; }
      .motion-example [data-loop-toggle] { display: none; }
    }

    @media (prefers-reduced-motion: reduce) { .flap-next, .flap-panel { display: none; } }
  </style>
</head>
<body>
  <main class="demo">
    <div class="motion-example">
      <div class="motion-specimen" aria-hidden="true"><div class="flap-time"><b>12<span>:</span></b><div class="flap-digit"><b>08</b><b class="flap-next" data-motion>09</b><b class="flap-panel" data-motion>08</b></div></div></div>
      <button class="demo-button" type="button" data-loop-toggle data-testid="effect-demo-loop-toggle">播放演示</button>
    </div>
  </main>
  <script>
    const example = document.querySelector('.motion-example');
    const toggle = example.querySelector('[data-loop-toggle]');

    toggle.addEventListener('click', () => {
      const playing = example.toggleAttribute('data-playing');
      toggle.textContent = playing ? "暂停演示" : "播放演示";
    });
  </script>
</body>
</html>

UI Skills 原创示例