X Tutup
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
10 changes: 5 additions & 5 deletions 02 - JS and CSS Clock/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@
background:black;
position: absolute;
top:50%;
transform-origin: 100%;
transform: rotate(90deg);
transition: all 0.5s;
transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
}

</style>

<script>


</script>
<script src="script.js"></script>
</body>
</html>
25 changes: 25 additions & 0 deletions 02 - JS and CSS Clock/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const hourHand = document.querySelector('.hour-hand');
const minuteHand = document.querySelector('.min-hand');
const secondHand = document.querySelector('.second-hand');

const rotateHand = (degrees) => {
return `rotate(${degrees}deg)`;
};

const setDate = () => {
const now = new Date();
const seconds = now.getSeconds();
const minutes = now.getMinutes();
const hours = now.getHours();

const secondDegrees = ((seconds / 60) * 360) + 90;
const minuteDegrees = ((minutes / 60) * 360) + 90;
const hourDegrees = ((hours / 12) * 360) + 90;

secondHand.style.transform = rotateHand(secondDegrees);
minuteHand.style.transform = rotateHand(minuteDegrees);
hourHand.style.transform = rotateHand(hourDegrees);
};

setInterval(setDate, 1000);
setDate();
X Tutup