-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (25 loc) · 1.04 KB
/
script.js
File metadata and controls
32 lines (25 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function playSound(e) {
const keyCode = e.keyCode || parseInt(this.getAttribute('data-key'));
const audio = document.querySelector(`audio[data-key="${keyCode}"]`);
const key = document.querySelector(`.drum[data-key="${keyCode}"]`);
if (!audio) return;
key.classList.add('playing');
audio.currentTime = 0;
audio.play();
}
function removeTransition(e) {
if (e.propertyName !== 'transform') return;
this.classList.remove('playing');
}
const keys = document.querySelectorAll('.drum');
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
keys.forEach(key => key.addEventListener('click', playSound)); // Added click support
window.addEventListener('keydown', playSound);
// Theme Switcher
const themeToggle = document.getElementById('theme-toggle');
const body = document.body;
themeToggle.addEventListener('click', () => {
body.classList.toggle('neon-theme');
const isNeon = body.classList.contains('neon-theme');
themeToggle.textContent = isNeon ? 'Theme: Neon' : 'Theme: Dark';
});