I am in the process of incorporating a countdown timer but with an analog clock rather than a digital one. My objective is to emphasize the next 25 minutes as a circle sector that commences from the minute hand on the clock.
Here is what I have developed so far: https://codepen.io/seifjo/pen/ExVQLOd
Below is the pertinent code extracted from the aforementioned codepen:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #68a4ff;
}
.clock {
width: 350px;
height: 350px;
display: flex;
align-items: center;
justify-content: center;
background: #bcd0e7;
border: 20px solid #fff;
border-radius: 50%;
background-size: cover;
box-shadow: inset 0 0 30px rgba(0, 0, 0, .2), 0 20px 20px rgba(0, 0, 0, .2), 0 0 0 4px rgba(255, 255, 255, 1);
}
.clock {
background-image: url(clock.png), linear-gradient(330deg, transparent 50%, #fff 50%), linear-gradient(540deg, #fff 50%, transparent 50%);
}
.clock::before {
content: '';
position: absolute;
width: 15px;
height: 15px;
background: #848484;
border: 2px solid #fff;
border-radius: 50%;
z-index: 10000;
}
.clock .hour,
.clock .min,
.clock .sec {
position: absolute;
}
.clock .hour,
.hr {
width: 160px;
height: 160px;
}
.clock .min,
.mn {
width: 190px;
height: 190px;
}
.clock .sec,
.sc {
width: 230px;
height: 230px;
}
.hr,
.mn,
.sc {
display: flex;
justify-content: center;
position: absolute;
border-radius: 50%;
}
.hr::before {
content: '';
position: absolute;
width: 8px;
height: 80px;
background: #848484;
z-index: 10;
border-radius: 6px 6px 0 0;
}
.mn:before {
content: '';
position: absolute;
width: 4px;
height: 90px;
background: #d6d6d6;
z-index: 11;
border-radius: 6px 6px 0 0;
}
.sc:before {
content: '';
position: absolute;
width: 2px;
height: 150px;
background: #ff6767;
z-index: 12;
border-radius: 6px 6px 0 0;
}
<div class="clock">
<div class="mask"></div>
<div class="hour">
<div class="hr" id="hr">
</div>
</div>
<div class="min">
<div class="mn" id="mn">
</div>
</div>
<div class="sec">
<div class="sc" id="sc">
</div>
</div>
</div>
<script>
const deg = 6;
const hr = document.querySelector("#hr");
const mn = document.querySelector("#mn");
const sc = document.querySelector("#sc");
setInterval(() => {
let day = new Date();
let hh = day.getHours() * 30;
let mm = day.getMinutes() * deg;
let ss = day.getSeconds() * deg;
hr.style.transform = `rotateZ(${(hh)+(mm/12)}deg)`;
mn.style.transform = `rotateZ(${mm}deg)`;
sc.style.transform = `rotateZ(${ss}deg)`;
}, 1000);
</script>
I have successfully indicated the next 25 minutes beginning from 3 o'clock. However, I am struggling to determine the relationship between the minutes and the degrees. Eventually, this will evolve into a react app where I will pass the current minute as a prop.