Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>
  <h1 id="title">🥁 Drum Kit 🥁</h1>
  <p>Please click button or press keyboard!</p>
  <div class="set">
    <button class="w drum">w</button>
    <button class="a drum">a</button>
    <button class="s drum">s</button>
    <button class="d drum">d</button>
    <button class="j drum">j</button>
    <button class="k drum">k</button>
    <button class="l drum">l</button>
  </div>
</body>

<footer>
  Made by Junghwa❤️
</footer>
              
            
!

CSS

              
                body {
  text-align: center;
  background-color: #6983aa;
}

h1, p, footer {
  color: #f6f4e6;
}

h1 {
  font-size: 5rem;
  font-family: 'Russo One', sans-serif;
  text-shadow: 4px 0 #d54062;
}

p, footer {
  font-family: 'Gochi Hand', cursive;
}

p {
  font-size: 1.7rem;
}

footer {
  font-size: 1.3rem;
}

.w {
  background-image: url("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/images/tom1.png");
}

.a {
  background-image: url("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/images/tom2.png");
}

.s {
  background-image: url("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/images/tom3.png");
}

.d {
  background-image: url("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/images/tom4.png");
}

.j {
  background-image: url("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/images/snare.png");
}

.k {
  background-image: url("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/images/crash.png");
}

.l {
  background-image: url("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/images/kick.png");
}

.set {
  margin: 10% auto;
}

.pressed {
  box-shadow: 0 3px 4px 0 #DBEDF3;
  opacity: 0.5;
}

.drum {
  outline: none;
  border: 10px solid #404B69;
  font-size: 5rem;
  font-family: 'Russo One', sans-serif;
  line-height: 2;
  font-weight: 700;
  color: #68b0ab;
  text-shadow: 3px 0 #d54062;
  border-radius: 1.5rem;
  display: inline-block;
  width: 150px;
  height: 150px;
  text-align: center;
}
              
            
!

JS

              
                const allButtons = document.querySelectorAll(".drum");

// Detecting button press
allButtons.forEach(button => {
  button.addEventListener("click", function() {
    const clickedButton = this.innerHTML;
    makeSound(clickedButton);
    buttonAnimation(clickedButton);
  });
});

// Detecting keyboard press
document.addEventListener("keydown", event => {
  const drumKeys = ["w", "a", "s", "d", "j", "k", "l"];
  if (drumKeys.includes(event.key)) {
    makeSound(event.key);
    buttonAnimation(event.key);
  }
});

function makeSound(key) {
  switch (key) {
    case "w":
      const tom1 = new Audio("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/sounds/tom-1.mp3");
      tom1.play();
      break;

    case "a":
      const tom2 = new Audio("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/sounds/tom-2.mp3");
      tom2.play();
      break;

    case "s":
      const tom3 = new Audio("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/sounds/tom-3.mp3");
      tom3.play();
      break;

    case "d":
      const tom4 = new Audio("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/sounds/tom-4.mp3");
      tom4.play();
      break;

    case "j":
      const snare = new Audio("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/sounds/snare.mp3");
      snare.play();
      break;

    case "k":
      const crash = new Audio("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/sounds/crash.mp3");
      crash.play();
      break;

    case "l":
      const kick = new Audio("https://project-assets.s3-ap-southeast-2.amazonaws.com/drum-kit/sounds/kick-bass.mp3");
      kick.play();
      break;
  }
}

function buttonAnimation(key) {
  const activeButton = document.querySelector(`.${key}`);
  activeButton.classList.add("pressed");
  setTimeout(() => {
    activeButton.classList.remove("pressed");
  }, 100);
}
              
            
!
999px

Console