added sound effects
This commit is contained in:
parent
d8b7bf27bf
commit
d071dad97a
10 changed files with 27 additions and 0 deletions
BIN
src/assets/effects/click_1.wav
Normal file
BIN
src/assets/effects/click_1.wav
Normal file
Binary file not shown.
BIN
src/assets/effects/hover_1.wav
Normal file
BIN
src/assets/effects/hover_1.wav
Normal file
Binary file not shown.
BIN
src/assets/effects/hover_2.wav
Normal file
BIN
src/assets/effects/hover_2.wav
Normal file
Binary file not shown.
BIN
src/assets/effects/hover_3.wav
Normal file
BIN
src/assets/effects/hover_3.wav
Normal file
Binary file not shown.
BIN
src/assets/effects/hover_4.wav
Normal file
BIN
src/assets/effects/hover_4.wav
Normal file
Binary file not shown.
BIN
src/assets/effects/hover_5.wav
Normal file
BIN
src/assets/effects/hover_5.wav
Normal file
Binary file not shown.
BIN
src/assets/effects/hover_6.wav
Normal file
BIN
src/assets/effects/hover_6.wav
Normal file
Binary file not shown.
25
src/assets/sound.js
Normal file
25
src/assets/sound.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
function load_effects(names) {
|
||||
return names.map(name => {
|
||||
let audio = document.createElement("audio");
|
||||
audio.src = `/assets/effects/${name}.wav`;
|
||||
audio.volume = 0.1;
|
||||
return audio;
|
||||
});
|
||||
}
|
||||
|
||||
function play_random(effects) {
|
||||
let index = Math.floor(Math.random() * effects.length);
|
||||
effects[index].pause();
|
||||
effects[index].play().catch(() => { });
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
let click_effects = load_effects(["click_1"]);
|
||||
let hover_effects = load_effects(["hover_1", "hover_2", "hover_3", "hover_4", "hover_5", "hover_6"]);
|
||||
let links = [...document.getElementsByTagName("a")];
|
||||
links.forEach(link => {
|
||||
link.addEventListener("mouseover", () => play_random(hover_effects));
|
||||
link.addEventListener("mousedown", () => play_random(click_effects));
|
||||
});
|
||||
})
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
<meta name="description" content="Home page of Frederik Palmø (vodofrede)" />
|
||||
<link rel="stylesheet" href="/assets/main.css" />
|
||||
<link rel="icon" type="image/x-icon " href="/assets/favicon.ico" />
|
||||
<script src="/assets/sound.js"></script>
|
||||
</head>
|
||||
|
||||
<body class="column separate" style="padding: 2%; gap: 15px">
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<meta name="description" content="Home page of Frederik Palmø (vodofrede)" />
|
||||
<link rel="stylesheet" href="/assets/main.css" />
|
||||
<link rel="icon" type="image/x-icon " href="/assets/favicon.ico" />
|
||||
<script src="/assets/sound.js"></script>
|
||||
</head>
|
||||
|
||||
<body class="column separate" style="padding: 2%; gap: 15px">
|
||||
|
|
Loading…
Reference in a new issue