# KMA Weather Nuri · 回放雷达图，观察降雨移动

在韩国气象厅的雷达页面设定时间间隔并点击播放，观测图就会按时间顺序切换。想看清某一刻的降雨位置时，再点一次即可暂停。

[官方来源](https://www.weather.go.kr/w/weather/radar/radar.do)

## 相关动效 · 时间轴拖动

# 时间轴拖动

沿时间轴拖动，逐个查看八秒短片中的画面。

## 试一试

播放短片，再拖动时间滑块，逐个检查画面。

## 交互细节

短片时长 8 秒，支持按 0.1 秒为步长定位。手动定位时暂停播放并保留选中的画面。从结尾播放会重新开始。

## 各平台的操作方式

- iOS · 在时间滑块上点按或拖动，对比不同画面。
- Android · 在时间滑块上点按或拖动，对比不同画面。
- PC · 拖动滑块，或聚焦后按左右方向键，每次移动 0.1 秒。

## 适用场景

短片回看、动画校对或需要精确定位的时间轴。

## 实现要求

> 手动定位时暂停播放，保留当前画面并更新经过时间。

## 来源与致谢

[W3C WAI · Media Seek Slider](<https://www.w3.org/WAI/ARIA/apg/patterns/slider/examples/slider-seek/>)

## 独立 HTML 示例

将以下代码保存为 HTML 文件，用浏览器打开即可离线体验。

```html
<!doctype html>
<html lang="zh-Hans"><head><script>if(new URLSearchParams(location.search).get('reduce')==='1')document.documentElement.classList.add('motion-reduced');</script><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>时间轴拖动 · Motion Lab</title>
<style>
*{box-sizing:border-box}body{margin:0;font-family:system-ui,-apple-system,"Malgun Gothic",sans-serif;word-break:keep-all}button,input{font:inherit}button{cursor:pointer}button:focus-visible,input:focus-visible,[tabindex]:focus-visible{outline:3px solid #ef7c30;outline-offset:2px}button:disabled{cursor:default}button{touch-action:manipulation}.sr-only{position:absolute;inline-size:1px;block-size:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
body{min-height:100svh;display:grid;place-items:center;padding:18px;background:#202627;color:#f6f0e1}
main{width:min(100%,690px)}header{display:flex;align-items:baseline;justify-content:space-between;gap:10px;padding:0 0 11px}h1{font-size:clamp(22px,4vw,34px);letter-spacing:-.06em;margin:0}.running-time{font:12px/1.3 monospace;color:#d0d6cc}
figure{margin:0;position:relative;overflow:hidden;background:#d5a075}.screen{position:relative;height:clamp(165px,51svh,300px)}canvas{display:block;width:100%;height:100%}.screen::after{content:"";position:absolute;inset:9px;border:1px solid #fff8;pointer-events:none}
figcaption{display:flex;justify-content:space-between;align-items:center;gap:10px;background:#eae5d6;color:#262927;padding:8px 12px;font:600 12px/1.3 monospace}figcaption em{font:italic 17px/1 Georgia,serif}
.transport{display:grid;grid-template-columns:auto minmax(0,1fr) auto;gap:12px;align-items:center;margin-top:7px}button{min-height:44px;padding:6px 10px;border:1px solid #737c77;background:transparent;color:#fff5dc;border-radius:4px;font-size:13px}button:hover{background:#353d38}#timeline{width:100%;height:44px;accent-color:#ffbb74;cursor:ew-resize;margin:0}output{white-space:nowrap;font:14px/1.35 monospace;font-variant-numeric:tabular-nums}.ticks{display:flex;justify-content:space-between;padding:0 2px 5px;border-bottom:1px solid #66716a;font:11px monospace;color:#ced2c7}
@media(max-width:420px){body{padding:11px}.transport{gap:6px}h1{font-size:23px}output{font-size:12px}.running-time{font-size:10px}}
@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:.001ms!important;transition-duration:.001ms!important;scroll-behavior:auto!important}}.motion-reduced *,.motion-reduced *::before,.motion-reduced *::after{animation-duration:.001ms!important;transition-duration:.001ms!important;scroll-behavior:auto!important}
</style></head><body>
<main><header><h1>沙丘山脊</h1><span class="running-time">8 秒动态短片</span></header>
<figure><div class="screen"><canvas id="film" role="img" aria-label="太阳与沙丘山脊随时间移动的动态版画"></canvas></div><figcaption><em lang="en">Dune passage</em><span id="frame">F 000</span></figcaption></figure>
<div class="transport"><button id="play" type="button">▶ 播放</button><input id="timeline" aria-label="播放位置" type="range" min="0" max="8" step="0.1" value="1.6"><output id="time" aria-live="off">1.6 秒</output></div><div class="ticks" aria-hidden="true"><span>0s</span><span>2s</span><span>4s</span><span>6s</span><span>8s</span></div></main>
<script>
const canvas=document.querySelector('#film'),ctx=canvas.getContext('2d'),range=document.querySelector('#timeline'),play=document.querySelector('#play');
const tau=Math.PI*2;
let time=1.6,raf=0,origin=0;
function blend(a,b,k){return 'rgb('+a.map((v,i)=>Math.round(v+(b[i]-v)*k)).join(',')+')';}
function draw(){
  const r=canvas.getBoundingClientRect(),dpr=Math.min(devicePixelRatio||1,2),width=Math.max(1,Math.round(r.width*dpr)),height=Math.max(1,Math.round(r.height*dpr));
  if(canvas.width!==width||canvas.height!==height){canvas.width=width;canvas.height=height;}
  ctx.setTransform(width/800,0,0,height/330,0,0);
  const t=time/8, late=t*t, x=105+t*595, y=190-Math.sin(Math.PI*t)*161;
  ctx.fillStyle=blend([231,181,128],[86,108,123],late);ctx.fillRect(0,0,800,330);
  ctx.fillStyle=blend([255,219,143],[248,162,97],late);ctx.beginPath();ctx.arc(x,y,44,0,tau);ctx.fill();
  for(let layer=0;layer<3;layer++){
    const profile=pos=>154+layer*44+Math.sin(pos/(130-layer*18)+layer*.7+t*(.95+layer*.9))*37+Math.cos(pos/62+t*(1+layer))*(8+layer*3);
    const fills=['#a56753','#764c43','#323b39'],inks=['#764d47','#513b37','#b3aa83'];
    ctx.beginPath();ctx.moveTo(0,330);
    for(let px=0;px<=800;px+=4)ctx.lineTo(px,profile(px));
    ctx.lineTo(800,330);ctx.closePath();ctx.fillStyle=fills[layer];ctx.fill();
    ctx.save();ctx.clip();ctx.lineWidth=1;ctx.strokeStyle=inks[layer];ctx.globalAlpha=layer===2?.6:.67;
    for(let n=0;n<35;n++){
      ctx.beginPath();
      for(let px=0;px<=800;px+=5){const py=profile(px)+n*(4+layer)+Math.sin(px/110+n*.21+t)*n*.45;if(!px)ctx.moveTo(px,py);else ctx.lineTo(px,py);}
      ctx.stroke();
    }
    ctx.restore();
  }
  range.value=time.toFixed(1);range.setAttribute('aria-valuetext',Math.round(time*10)/10+' 秒，共 8 秒');
  document.querySelector('#time').textContent=time.toFixed(1)+' 秒';
  document.querySelector('#frame').textContent='F '+String(Math.round(time*24)).padStart(3,'0');
}
function pause(){cancelAnimationFrame(raf);raf=0;play.textContent='▶ 播放';play.setAttribute('aria-label','播放');}
function tick(now){time=Math.min(8,(now-origin)/1000);draw();if(time<8)raf=requestAnimationFrame(tick);else pause();}
play.onclick=()=>{if(raf){pause();return;}if(time>=8)time=0;origin=performance.now()-time*1000;play.textContent='Ⅱ 暂停';play.setAttribute('aria-label','暂停');raf=requestAnimationFrame(tick);};
range.addEventListener('pointerdown',pause);range.addEventListener('input',()=>{pause();time=Number(range.value);draw();});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();});
new ResizeObserver(draw).observe(canvas);draw();
</script></body></html>
```
