Visitar URL original
finished day 1 drum kit and day 2 JS and CSS clock · wesbos/JavaScript30@63d9886 · GitHub
Skip to content

Commit 63d9886

Browse files
committed
finished day 1 drum kit and day 2 JS and CSS clock
1 parent b8bc9cb commit 63d9886

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

‎01 - JavaScript Drum Kit/index-START.html‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,26 @@
5959

6060
<script>
6161

62+
function playSound(e) {
63+
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
64+
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
65+
console.log(audio);
66+
if(!audio) return;
67+
audio.currentTime = 0;
68+
audio.play();
69+
key.classList.add('playing')
70+
};
71+
72+
function removeTransition(e){
73+
if (e.propertyName !== 'transform') return; //skip if it isn't transforming
74+
this.classList.remove('playing');
75+
}
76+
77+
const keys = document.querySelectorAll('.key');
78+
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
79+
window.addEventListener('keydown', playSound);
80+
81+
6282
</script>
6383

6484

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,34 @@
6161
background:black;
6262
position: absolute;
6363
top:50%;
64+
transform-origin: 100%;
65+
transform: rotate(90deg);
66+
transition: all 0.5s;
67+
transition-timing-function: cubic-bezier(0.34, 2.1, 0.58, 1);
6468
}
6569

6670
</style>
6771

6872
<script>
73+
const secondHand = document.querySelector('.second-hand');
74+
const minuteHand = document.querySelector('.min-hand');
75+
const hourHand = document.querySelector('.hour-hand');
6976

77+
function setDate() {
78+
// console.log("Hi");
79+
const now = new Date();
80+
const secs = now.getSeconds();
81+
const hour = now.getHours();
82+
const min = now.getMinutes();
83+
const secsDegrees = ((secs / 60) * 360) + 90;
84+
const minDegrees = ((min / 60) * 360) + 90;
85+
const hourDegrees = (((hour % 12) / 12) * 360) + 90;
86+
secondHand.style.transform = `rotate(${secsDegrees}deg)`;
87+
minuteHand.style.transform = `rotate(${minDegrees}deg)`;
88+
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
89+
}
90+
91+
setInterval(setDate, 1000);
7092

7193
</script>
7294
</body>

0 commit comments

Comments
 (0)