From d8c5627cf8279fa4e0c50691f10d9e0ca4db9468 Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 3 Oct 2024 18:34:43 -0500 Subject: [PATCH] Update audio player volume slider to be vertical --- client/components/controls/VolumeControl.vue | 43 ++++++++------------ client/components/player/PlayerUi.vue | 2 +- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/client/components/controls/VolumeControl.vue b/client/components/controls/VolumeControl.vue index 220cccaa..a29ee7d1 100644 --- a/client/components/controls/VolumeControl.vue +++ b/client/components/controls/VolumeControl.vue @@ -4,10 +4,10 @@ {{ volumeIcon }} -
-
-
-
+
+
+
+
@@ -24,10 +24,10 @@ export default { isOpen: false, isDragging: false, isHovering: false, - posX: 0, + posY: 0, lastValue: 0.5, isMute: false, - trackWidth: 112 - 20, + trackHeight: 112 - 20, openTimeout: null } }, @@ -45,9 +45,9 @@ export default { this.$emit('input', val) } }, - cursorLeft() { - var left = this.trackWidth * this.volume - return left - 3 + cursorBottom() { + var bottom = this.trackHeight * this.volume + return bottom - 3 }, volumeIcon() { if (this.volume <= 0) return 'volume_mute' @@ -89,17 +89,10 @@ export default { }, 600) }, mousemove(e) { - var diff = this.posX - e.x - this.posX = e.x - var volShift = 0 - if (diff < 0) { - // Volume up - volShift = diff / this.trackWidth - } else { - // volume down - volShift = diff / this.trackWidth - } - var newVol = this.volume - volShift + var diff = this.posY - e.y + this.posY = e.y + var volShift = diff / this.trackHeight + var newVol = this.volume + volShift newVol = Math.min(Math.max(0, newVol), 1) this.volume = newVol e.preventDefault() @@ -113,8 +106,8 @@ export default { }, mousedownTrack(e) { this.isDragging = true - this.posX = e.x - var vol = e.offsetX / this.trackWidth + this.posY = e.y + var vol = 1 - e.offsetY / this.trackHeight vol = Math.min(Math.max(vol, 0), 1) this.volume = vol document.body.addEventListener('mousemove', this.mousemove) @@ -137,7 +130,7 @@ export default { this.clickVolumeIcon() }, clickVolumeTrack(e) { - var vol = e.offsetX / this.trackWidth + var vol = 1 - e.offsetY / this.trackHeight vol = Math.min(Math.max(vol, 0), 1) this.volume = vol } @@ -147,7 +140,7 @@ export default { this.isMute = true } const storageVolume = localStorage.getItem('volume') - if (storageVolume) { + if (storageVolume && !isNaN(storageVolume)) { this.volume = parseFloat(storageVolume) } }, @@ -157,4 +150,4 @@ export default { document.body.removeEventListener('mouseup', this.mouseup) } } - \ No newline at end of file + diff --git a/client/components/player/PlayerUi.vue b/client/components/player/PlayerUi.vue index 689dd31a..92179580 100644 --- a/client/components/player/PlayerUi.vue +++ b/client/components/player/PlayerUi.vue @@ -4,7 +4,7 @@
- +