250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- jQuery
- button
- front-end
- php
- 자바스크립트
- html5
- ipad
- 프론트엔드
- SWIFT
- 비전공자
- HTML
- image
- css3
- iPhone
- effect
- IOS
- CSS
- iOS 개발자
- 개발자
- Animation
- javascript
- 애니메이션
- 백엔드
- 비전공 개발자
- MAC
- hover
- react
- 풀스택
- xcode
- keyframes
Archives
- Today
- Total
비전공자 개발일기
Javascript - Sound Board 본문
728x90
SMALL
<!DOCTYPE html>
<html lang="ko">
<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>Sound Board</title>
<link rel="stylesheet" href="style.css">
<script defer src="main.js"></script>
</head>
<body>
<audio id="applause" src="./sounds/applause.mp3"></audio>
<audio id="boo" src="./sounds/boo.mp3"></audio>
<audio id="gasp" src="./sounds/gasp.mp3"></audio>
<audio id="tada" src="./sounds/tada.mp3"></audio>
<audio id="victory" src="./sounds/victory.mp3"></audio>
<audio id="wrong" src="./sounds/wrong.mp3"></audio>
<div id="buttons"></div>
</body>
</html>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;400&display=swap');
* {
box-sizing: border-box;
}
body {
background-color: rgb(161, 100, 223);
font-family: 'Poppins', sans-serif;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
text-align: center;
height: 100vh;
overflow: hidden;
margin: 0;
}
.btn {
background-color: #663399;
border-radius: 5px;
border: none;
color: #fff;
margin: 1rem;
padding: 1.5rem 3rem;
font-size: 1.2rem;
font-family: inherit;
cursor: pointer;
}
.btn:hover {
opacity: .9;
}
.btn:focus {
outline: none;
}
const sounds = ["applause", "boo", "gasp", "tada", "victory", "wrong"];
sounds.forEach(sound => {
const btn = document.createElement("button");
btn.classList.add("btn");
btn.innerText = sound;
btn.addEventListener("click", () => {
stopSongs();
document.getElementById(sound).play();
})
document.getElementById("buttons").appendChild(btn);
})
function stopSongs() {
sounds.forEach(sound => {
const song = document.getElementById(sound);
song.pause();
song.currentTime = 0;
})
}
728x90
LIST
'Javascript' 카테고리의 다른 글
Javascript - Event Keycodes (0) | 2021.10.04 |
---|---|
Javascript - Dad Jokes (0) | 2021.10.03 |
Javascript - Form Wave Animation (0) | 2021.10.01 |
Javascript - Split Landing Page (0) | 2021.09.30 |
Javascript - Scroll Animation (0) | 2021.09.29 |