Skip to content

时钟旋转 Clock

模拟时钟指针旋转的加载动画,时针和分针以不同速度匀速转动,表盘简洁而优雅。

实时预览

代码

css
.clock {
  width: 80px;
  height: 80px;
}

.clock-face {
  position: relative;
  width: 80px;
  height: 80px;
  border: 2px solid rgba(64, 184, 131, 0.5);
  border-radius: 50%;
}

.clock-hand {
  position: absolute;
  bottom: 50%;
  left: 50%;
  transform-origin: bottom center;
  border-radius: 2px;
}

.hour-hand {
  width: 3px;
  height: 20px;
  margin-left: -1.5px;
  background: #40b883;
  animation: clock-hour 12s linear infinite;
}

.minute-hand {
  width: 2px;
  height: 28px;
  margin-left: -1px;
  background: rgba(64, 184, 131, 0.6);
  animation: clock-minute 3s linear infinite;
}

.clock-center-dot {
  position: absolute;
  top: 50%; left: 50%;
  width: 6px; height: 6px;
  margin: -3px 0 0 -3px;
  background: #40b883;
  border-radius: 50%;
  z-index: 2;
}

.clock-tick {
  position: absolute;
  top: 4px; left: 50%;
  width: 2px; height: 6px;
  margin-left: -1px;
  background: rgba(64, 184, 131, 0.4);
  transform-origin: center 36px;
}

.tick-1  { transform: rotate(30deg); }
/* ... tick-2 through tick-12 at 30deg increments ... */

@keyframes clock-hour {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes clock-minute {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
html
<div class="clock">
  <div class="clock-face">
    <div class="clock-hand hour-hand"></div>
    <div class="clock-hand minute-hand"></div>
    <div class="clock-center-dot"></div>
    <div class="clock-tick tick-1"></div>
    <!-- ... tick-2 through tick-12 ... -->
  </div>
</div>

纯 CSS 实现的时钟旋转加载动画——通过 @keyframesanimation 属性创建循环播放的加载指示器。比 GIF 体积更小、缩放不失真,完全不需要 JavaScript。

快速使用

  1. 复制 CSS 代码到你的样式文件(含 @keyframes 定义)
  2. 在需要显示加载状态的位置添加 HTML 结构
  3. 调整 width/height 控制大小,animation-duration 控制速度
  4. 数据加载完成后移除 loading 元素,释放 GPU 资源

使用场景

  • 页面初始加载:在 SPA 或内容较重的页面中,用骨架屏或旋转动画代替白屏等待
  • 数据请求等待:按钮提交后显示加载状态,防止重复点击
  • 文件上传/下载:配合进度条或环形进度指示操作进度
  • 无限滚动加载更多:页面底部显示加载指示器,告知用户内容正在加载

常见问题

Q: Loading 动画什么时候需要停止? A: 数据加载完成后,通过 JavaScript 移除动画元素的 class 或直接移除 DOM 元素。可以给元素加 animation: none 立即停止动画,释放 GPU 资源。

Q: 多个 Loading 元素会互相影响吗? A: 不会。每个 CSS animation 相互独立。但如果页面同时有 20+ 个动画元素,移动端可能出现卡顿。建议一个页面只保留 1-2 个主 loading 指示器。

Q: 如何让 Loading 动画适应不同尺寸? A: 所有尺寸用相对单位或无单位值。建议用 CSS 自定义属性(如 --loader-size: 48px)统一控制,方便全局调整。

浏览器兼容性

本效果使用标准 CSS 属性,所有现代浏览器(Chrome、Firefox、Safari、Edge)均完全支持。

浏览器兼容性
Chrome / Edge✅ 完全支持
Firefox✅ 完全支持
Safari✅ 完全支持
移动端浏览器✅ 完全支持
IE 11⚠️ 部分 @keyframes / animation 需要 -ms- 前缀

使用说明

属性说明
transform-origin必须为 bottom center,指针围绕底部旋转
hour-hand 周期时针旋转周期较长(如 12s),视觉上更慢
minute-hand 周期分针旋转周期较短(如 3s),形成速度差
刻度数量12 个刻度均匀分布,每个间隔 30°
border表盘边框,调整粗细和颜色