-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
63 lines (54 loc) · 1.83 KB
/
Copy pathindex.html
File metadata and controls
63 lines (54 loc) · 1.83 KB
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
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<head>
<title>fumo</title>
<style>
.colored {
filter: grayscale(0%);
transition: filter 0.5s;
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
.grayscale {
filter: grayscale(100%);
transition: filter 0.5s;
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
</style>
</head>
<body>
<img id="image" class="grayscale" src="img/fumo.jpg" alt="Image 1" onclick="toggleImage('image', 'audio')">
<audio id="audio" src="audio/fumo.mp3"></audio>
<script>
var audioElements = document.querySelectorAll('audio');
var imageElements = document.querySelectorAll('img');
for (var i = 0; i < audioElements.length; i++) {
audioElements[i].addEventListener('ended', function() {
for (var j = 0; j < imageElements.length; j++) {
imageElements[j].classList.remove('colored');
imageElements[j].classList.add('grayscale');
}
});
}
function toggleImage(imageId, audioId) {
var image = document.getElementById(imageId);
var audio = document.getElementById(audioId);
if (image.classList.contains('grayscale')) {
image.classList.remove('grayscale');
image.classList.add('colored');
audio.play();
} else {
image.classList.remove('colored');
image.classList.add('grayscale');
audio.pause();
audio.currentTime = 0;
}
}
</script>
</body>
</html>