Skip to content

Fixed Drum kit bug #452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
12 changes: 4 additions & 8 deletions 01 - JavaScript Drum Kit/index-FINISHED.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,19 @@
<audio data-key="76" src="sounds/tink.wav"></audio>

<script>
function removeTransition(e) {
if (e.propertyName !== 'transform') return;
e.target.classList.remove('playing');
}

function playSound(e) {
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
const key = document.querySelector(`div[data-key="${e.keyCode}"]`);
if (!audio) return;

key.classList.add('playing');
key.style.animationPlayState = 'running';
var elm = key;
var newone = elm.cloneNode(true);
elm.parentNode.replaceChild(newone, elm);
audio.currentTime = 0;
audio.play();
}

const keys = Array.from(document.querySelectorAll('.key'));
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
window.addEventListener('keydown', playSound);
</script>

Expand Down
27 changes: 20 additions & 7 deletions 01 - JavaScript Drum Kit/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,39 @@ body,html {
justify-content: center;
}

@keyframes highlight {
0% {
border: .4rem solid black;
width: 10rem;
}
50% {
border: .6rem solid #ffc600;
box-shadow: 0 0 1rem #ffc600;
transform: scale(1.1);
}
100% {
border: .4rem solid black;
width: 10rem;
}
}

.key {
border: .4rem solid black;
border-radius: .5rem;
margin: 1rem;
font-size: 1.5rem;
padding: 1rem .5rem;
transition: all .07s ease;
animation-name: highlight;
animation-duration: 0.07s;
animation-fill-mode: forwards;
animation-play-state: paused;
width: 10rem;
text-align: center;
color: white;
background: rgba(0,0,0,0.4);
text-shadow: 0 0 .5rem black;
}

.playing {
transform: scale(1.1);
border-color: #ffc600;
box-shadow: 0 0 1rem #ffc600;
}

kbd {
display: block;
font-size: 4rem;
Expand Down