Skip to content

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
added button animation
  • Loading branch information
AtulTiwari02 authored Nov 6, 2023
1 parent 3ae0655 commit 30bfc5e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ for(var i = 0; i < document.querySelectorAll(".drum").length; i++){
var buttonHTML = this.innerHTML;
makeSound(buttonHTML);

buttonAnimation(buttonHTML);
});
}

document.addEventListener("keypress",function(event){
makeSound(event.key);

buttonAnimation(event.key);
});


Expand Down Expand Up @@ -50,3 +53,13 @@ for(var i = 0; i < document.querySelectorAll(".drum").length; i++){

}

function buttonAnimation(clickedKey){
var activeKey = document.querySelector("." + clickedKey);

activeKey.classList.add("pressed");

setTimeout(function(){
activeKey.classList.remove("pressed");
}, 100);
}

0 comments on commit 30bfc5e

Please sign in to comment.