Skip to content

Commit 83835a5

Browse files
Eric LeeEric Lee
authored andcommitted
Did project 2 and added README comments
1 parent b177e36 commit 83835a5

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

02 - JS + CSS Clock/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Goal:
2+
3+
Learn how to manipulate CSS aspects through JavaScript.
4+
5+
## Summary:
6+
7+
CSS elements can be edited through getting the class elements with querySelector and changing the style attribute of the class element. For us, we changed the style.transform attribute, calling the rotate method and changing each time-hand type with their respective degrees (hour, min, second). We made sure that this function change updated the hand's position would only be called at given interval times (every 1 sec). We set the transform origin to 100% so that the hand would rotate based on the x axis of the image. Additionally, we changed the transition for all hands to be 0.05 seconds so they would have a mini buffer time. Furthermore, we changeed the transition-timing-function based on the cubic-bezier function (changing some values through a simple interface.) so that the change would have some repetitive backwards/forwards motion to mimic the clock hands jittery movement.
8+
9+
**NOTE:** There is a small choke for the program when the seconds reach 0. At that point, the second (and potentially minute/hour) hand causes a very abrupt stutter in the UI update. Can be fixed with some simple if/else statements
10+
11+
12+
## One Thing Learned:
13+
14+
JavaScript scripts are not to difficult to make, but creating the initial interface and design takes quite some time. Fortunately these proejcts come with sample code, making it easy just to focus on the back-end code.
15+

02 - JS + CSS Clock/index-START.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,35 @@
6161
background:black;
6262
position: absolute;
6363
top:50%;
64+
transform-origin: 100%;
65+
transition: all 0.05s;
66+
transition-timing-function: cubic-bezier(0.23, 1.92, 0.58, 1);
6467
}
6568

6669
</style>
6770

6871
<script>
72+
const secondHand = document.querySelector('.second-hand');
73+
const minHand = document.querySelector('.min-hand');
74+
const hourHand = document.querySelector('.hour-hand');
6975

76+
function setDate() {
77+
const now = new Date();
78+
const seconds = now.getSeconds();
79+
const secondsDegrees = ((seconds / 60) * 360) + 90;
80+
secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
81+
82+
const minutes = now.getMinutes();
83+
const minutesDegrees = (minutes * 6) + 90;
84+
minHand.style.transform = `rotate(${minutesDegrees}deg)`;
85+
86+
const hours = now.getHours();
87+
const hoursDegrees = (hours * 30) + 90;
88+
hourHand.style.transform = `rotate(${hoursDegrees}deg)`;
89+
90+
}
91+
92+
setInterval(setDate, 1000);
7093

7194
</script>
7295
</body>

0 commit comments

Comments
 (0)