-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCounter.svelte
57 lines (50 loc) · 1.07 KB
/
Counter.svelte
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<script lang="ts">
import { Sound, sound } from "svelte-sound";
import click_mp3 from "../assets/click.mp3";
let count: number = 0;
const increment = () => {
count += 1;
};
const clickSound = new Sound(click_mp3); // this is reusable sound
function handleClick() {
clickSound.play();
setTimeout(() => {
clickSound.play();
count += 1; // this is to accompany the double click sound
}, 400);
}
</script>
<div>
<div class="button">
Action
<button
on:click={increment}
use:sound={{ src: click_mp3, events: ["click"] }}
>
count is {count}
</button>
<span> (single click sound) </span>
</div>
<div class="button">
Manual Sound
<button on:click={increment} on:click={handleClick}>
count is {count}
</button>
<span> (double click sound) </span>
</div>
</div>
<style>
div {
display: flex;
flex-direction: row;
justify-content: space-around;
}
.button {
display: inline-flex;
flex-direction: column;
}
span {
font-size: 0.8em;
color: #999;
}
</style>