核心
- 读秒:
- let now = new Date()
- let seconds = now.getSeconds()
- let minutes = now.getMinutes()
- let hours = now.getHours()
- 计算指针旋转的度数
- let secondsDeg = ((seconds /60) * 360) + 90 // 这是分针
- let minutesDeg = ((minutes / 60) _ 360) + ((seconds / 60) _ 6) + 90 // 这是秒针
- let hoursDeg = ((hours / 12) _ 360) + ((minutes / 60) _ 30) + 90 // 这是时针
- 设置指针角度
- 时/分/秒指针 dom.style.transform =
rotate(${secondsDeg/minutesDeg/hoursDeg}deg)
- 时/分/秒指针 dom.style.transform =