mouse wheel on volume slider

This commit is contained in:
Evert Prants 2018-10-05 16:44:03 +03:00
parent b8d4cf6fa1
commit a07de062cd
Signed by: evert
GPG Key ID: 1688DA83D222D0B5

View File

@ -10,6 +10,7 @@
var mute = document.querySelector('#player-mute') var mute = document.querySelector('#player-mute')
var vol = document.querySelector('#player-volbar') var vol = document.querySelector('#player-volbar')
var volBar = document.querySelector('#player-volbar .seek-inner') var volBar = document.querySelector('#player-volbar .seek-inner')
var volElem = document.querySelector('.volume')
// Seconds into HH:MM:SS // Seconds into HH:MM:SS
function toHHMMSS (numbr) { function toHHMMSS (numbr) {
@ -173,11 +174,25 @@
mute.addEventListener('click', function (e) { mute.addEventListener('click', function (e) {
audio.muted = !audio.muted audio.muted = !audio.muted
updateVolume()
}, false) }, false)
registerSeekBar(seek, 'currentTime', 'duration') registerSeekBar(seek, 'currentTime', 'duration')
registerSeekBar(vol, 'volume') registerSeekBar(vol, 'volume')
function wheelVolume (e) {
var delta = e.wheelDelta || -e.detail
if (delta < -1) delta = -1
if (delta > 1) delta = 1
let av = audio.volume + (delta / 10)
if (av > 1) av = 1
if (av < 0) av = 0
audio.volume = av
}
volElem.addEventListener('DOMMouseScroll', wheelVolume, false)
volElem.addEventListener('mousewheel', wheelVolume, false)
updateVolume() updateVolume()
})() })()