From 30bfc5ef121bbd888f4a776f5ac535fa02c06ea7 Mon Sep 17 00:00:00 2001 From: AtulTiwari02 <122714971+Atul0002@users.noreply.github.com> Date: Mon, 6 Nov 2023 22:11:28 +0545 Subject: [PATCH] Update index.js added button animation --- index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/index.js b/index.js index deab76e..6c3f7f8 100644 --- a/index.js +++ b/index.js @@ -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); }); @@ -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); + } +