Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions clock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
setInterval(setClock, 1000)

//first get element to be able to do stuff with it
const hourRotation = document.getElementById("hour")
const minuteRotation = document.getElementById("minute")
const secondRotation = document.getElementById("second")

function setClock () {
const currentDate = new Date()
const seconds = currentDate.getSeconds() /60
const minutes = (seconds + currentDate.getMinutes()) / 60
const hours = (minutes + currentDate.getHours()) / 12

setRotation(secondRotation, seconds)
setRotation(minuteRotation, minutes)
setRotation(hourRotation, hours)
}

function setRotation(element, rotationRatio) {
element.style.setProperty('--rotation', rotationRatio * 360)
}

setClock()



2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<body>
<div id="clock">
<img id="face" src="img/clockface.png"/>
<img id="second" src="img/second-hand.png"/>
<img id="minute" src="img/minute-hand.png"/>
<img id="hour" src="img/hour-hand.png"/>
<img id="second" src="img/second-hand.png"/>
</div>
<script src="clock.js"></script>
</body>
Expand Down
21 changes: 21 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
#clock {

}

#clock img {
position: absolute;

}

#hour {
position: absolute;
transform: rotate(calc(var(--rotation)* 1deg));

}



#minute {
position: absolute;
transform: rotate(calc(var(--rotation)* 1deg));
}




#second {
position: absolute;
transform: rotate(calc(var(--rotation)* 1deg));

}

#face {
position: relative;

}