-
Notifications
You must be signed in to change notification settings - Fork 549
Closed
Description
妹纸哎,好稀有,棒棒的。
第二个案例使用的是 transform 那几个指针到 0 秒/分/时 的时候,会变成0,然后指针就从 450deg -> 90deg ,有个跳顿的情况
let secondDeg = 0,
minDeg = 0,
hourDeg = 0
setDate()
function setDate() {
const date = new Date()
const second = date.getSeconds()
secondDeg = 90 + (second / 60) * 360
const min = date.getMinutes()
minDeg = 90 + (min / 60) * 360 + ((second / 60) / 60) * 360
const hour = date.getHours()
hourDeg = 90 + (hour / 12) * 360 + ((min / 60) / 12) * 360 + (((second / 60) / 60) / 12) * 360
changeDate(secondDeg, minDeg, hourDeg)
}
function updateDate() {
secondDeg += (1 / 60) * 360
minDeg += ((1 / 60) / 60) * 360
hourDeg += (((1 / 60) / 60) / 12)
changeDate(secondDeg, minDeg, hourDeg)
}
function changeDate(s, m, h) {
secHand.style.transform = `rotate(${ s }deg)`
minHand.style.transform = `rotate(${ m }deg)`
hourHand.style.transform = `rotate(${ h }deg)`
}
setInterval(updateDate, 1000)
我这里打算 setDate 初始化时间以后,一秒一秒地 updateDate 去改变时间
Metadata
Metadata
Assignees
Labels
No labels