Drum Kits Using HTML, CSS & JavaScript


Hello wizards, I hope you are doing great. Today in this blog you’ll learn how to create the "Drum Kits" project using HTML, CSS & JavaScript. 

Preview 


In the above video, you’ve seen the preview of the "Drum Kits" project and I hope now you are able to create this type of project. If not, I have provided all the HTML CSS and JavaScript code below. 

Drum Kits [Source Code] 

To get the following HTML, CSS & JS code for the Drum Kits project. You need to create three files one is a HTML file, second one is a CSS file and the another one is JS file. After creating these three files then you can copy-paste the given codes on your document. 

Remember, you’ve to create a file with .html extension for HTML code, .css extension for CSS code and .js for JavaScript code.

You can also download all source code files from the given download button.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Drum Kits</title>
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css">

</head>

<body>
    <h1>Drum Kits <i class="fas fa-drum"></i></h1>
    <div class="container">
    </div>
    <script src="index.js"></script>
</body>

</html>
CSS
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700;800;900&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  height: 100vh;
  background-color: yellow;
}

h1 {
  font-style: 50px;
  letter-spacing: 4px;
  color: black;
  white-space: nowrap;
  text-shadow: 4px 4px 10px rgba(0, 0, 0, 0.3);
}

.container {
  text-align: center;
}

.btn {
  border: none;
  padding: 30px 50px;
  margin: 10px;
  background-color: white;
  font-size: 20px;
  min-width: 200px;
  border-radius: 10px;
  box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.3), -4px -4px 8px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
  font-weight: 500;
  text-transform: capitalize;
  background-size: cover;
  background-repeat: no-repeat;
}

.btn:active {
  background-size: 105%;
}
JavaScript
const kits = ["kick","tom","crash","snare"];
const containerEl = document.querySelector(".container")

kits.forEach((kit)=>{
    const btnEl = document.createElement("button");
    btnEl.classList.add("btn");
    containerEl.appendChild(btnEl);
    btnEl.innerText = kit
    btnEl.style.backgroundImage = `url(images/${kit}.png)`
    const audioEl = document.createElement("audio");
    audioEl.src = `sounds/${kit}.mp3`;
    containerEl.appendChild(audioEl);

    btnEl.addEventListener("click",()=>{
        audioEl.play()
    })

    // We can also get the sound of instrument by using starting letter of instrument.
    document.addEventListener("keydown",(e)=>{
        if(e.key === kit.slice(0,1)){
            audioEl.play();
            btnEl.style.transform = "scale(0.9)";
        }
        setTimeout(() => {
            btnEl.style.transform = "scale(1)";
        }, 100);
    })
});
You have to wait 15 seconds.

Generating Download Link...

Post a Comment

Previous Post Next Post