JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<div></div>
<div></div>
<div></div>
</div>
CSS
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
background: url('https://stmed.net/sites/default/files/sky-wallpapers-28043-2711012.jpg'), linear-gradient(to bottom, #1e528e 0%, #265889 50%, #9da671 100%);
background-repeat: no-repeat;
background-attachment: fixed;
}
div {
border-radius: 50%;
}
body > div {
border: 20px solid white;
width: 300px;
height: 300px;
border-radius: 50%;
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
margin: auto;
}
div div:first-child {
margin: auto;
width: 3px;
background-color: black;
height: 49%;
position: absolute;
left: 0;
right: 0;
bottom: 50%;
transform: rotate(180deg);
transform-origin: 50% 100%;
transition: transform 0.5s;
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1) !important;
}
div:nth-child(2) {
width: 5px;
background-color: black;
height: 46%;
position: absolute;
left: 0;
right: 0;
bottom: 50%;
margin: auto;
transform: rotate(360deg);
transform-origin: 50% 100%;
transition: transform 2s;
}
div:nth-child(3) {
width: 5px;
background-color: black;
height: 43%;
position: absolute;
left: 0;
right: 0;
bottom: 50%;
margin: auto;
transform: rotate(360deg);
transform-origin: 50% 100%;
transition: transform 3s;
}
JavaScript
var secHand = document.querySelector('div div:first-child');
var minHand = document.querySelector('div:nth-child(2)');
var hourHand = document.querySelector('div:nth-child(3)');
var myVar = setInterval(myTimer, 1000);
function myTimer() {
var d = new Date();
function updateHands() {
secHand.style.transform = `rotate(${d.getSeconds()*6}deg)`;
minHand.style.transform = `rotate(${d.getMinutes()*6}deg)`;
hourHand.style.transform = `rotate(${d.getHours()*(360/12) + d.getMinutes()*6*6/360}deg)`;
}
// I tried this but I don't know how to make it work properly.
if (d.getSeconds() == 0) {
secHand.style.transform = 'rotate(360deg)';
secHand.addEventListener('transitionend', function(e){
e.target.removeEventListener(e.type, arguments.callee);
this.style.transition = 'transform 0s';
var localyRechunk = function(callBack) {
updateHands();
callBack();
};
localyRechunk(function() {
console.log('give back the transition');
});
})
}
else updateHands();
}