No title

 

#clock { width: 300px; height: 300px; border-radius: 50%; background-color: #eee; position: relative; } .clock-face { width: 100%; height: 100%; position: relative; } .hand { width: 2px; height: 50%; background-color: #333; position: absolute; top: 50%; transform-origin: 100%; } .hour-hand { width: 5px; } .minute-hand { width: 3px; } .second-hand { width: 1px; background-color: #f00; } const clock = document.getElementById('clock'); const hourHand = clock.querySelector('.hour-hand'); const minuteHand = clock.querySelector('.minute-hand'); const secondHand = clock.querySelector('.second-hand'); function setTime() { const currentTime = new Date(); const hours = currentTime.getHours(); const hoursDegrees = (hours / 12) * 360 + 90; hourHand.style.transform = `rotate(${hoursDegrees}deg)`; const minutes = currentTime.getMinutes(); const minutesDegrees = (minutes / 60) * 360 + 90; minuteHand.style.transform = `rotate(${minutesDegrees}deg)`; const seconds = currentTime.getSeconds(); const secondsDegrees = (seconds / 60) * 360 + 90; secondHand.style.transform = `rotate(${secondsDegrees}deg)`; } setInterval(setTime, 1000);

Post a Comment

Previous Post Next Post