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