added sound effects

This commit is contained in:
Frederik Palmø 2024-03-26 12:38:18 +01:00
parent d8b7bf27bf
commit d071dad97a
10 changed files with 27 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

25
src/assets/sound.js Normal file
View 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));
});
})

View File

@ -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">

View File

@ -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">