-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (33 loc) · 1.43 KB
/
app.js
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
document.addEventListener('DOMContentLoaded', function () {
const volumeSlider = document.getElementById('volumeSlider');
const volumePercentage = document.getElementById('volumePercentage');
const speakersDown = document.querySelector('.speakers-down');
const speakersUp = document.querySelector('.speakers-up');
volumeSlider.addEventListener('input', function () {
const value = this.value;
updateVolume(value);
});
// Add mouse wheel event to adjust the slider
volumeSlider.addEventListener('wheel', function (event) {
event.preventDefault();
const delta = -Math.sign(event.deltaY); // Invert the direction of the wheel scroll
const step = 5; // Adjust the step value as needed
// Update the slider value based on the wheel scroll direction
const newValue = parseInt(volumeSlider.value, 10) + delta * step;
const clampedValue = Math.min(100, Math.max(0, newValue));
updateVolume(clampedValue);
});
volumeSlider.addEventListener('dblclick', function () {
updateVolume(50); // Set volume to 50 on double click
});
speakersDown.addEventListener('click', function () {
updateVolume(0); // Set volume to 0 when speakers down is clicked
});
speakersUp.addEventListener('click', function () {
updateVolume(100); // Set volume to 100 when speakers up is clicked
});
function updateVolume(value) {
volumeSlider.value = value;
volumePercentage.textContent = value;
}
});