
- Tutorial Code to create a working clock using just HTML, CSS & javascript.
.
- Open index.html in browser. If any code is changed the browser needs to be refreshed.
- function to calculate position of clock hands using new Date().
function setDate() {
const now = new Date();
console.log('now', now);
const seconds = now.getSeconds();
const secondsDegrees = ((seconds / 60) * 360) + 90;
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
const mins = now.getMinutes();
const minsDegrees = ((mins / 60) * 360) + ((seconds/60)*6) + 90;
minsHand.style.transform = `rotate(${minsDegrees}deg)`;
const hours = now.getHours();
const hoursDegrees = ((hours / 12) * 360) + ((mins/60)*30) + 90;
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
}
- Uses cubic-bezier CSS library for ease-in and ease-out of ticking clock hands.
- Status: Working
- To-Do: Nothing