Add player seek progress bar

This commit is contained in:
wvffle 2022-07-25 02:05:33 +00:00 committed by Georg Krause
parent 801c04c07e
commit 8aa073b976
5 changed files with 30 additions and 25 deletions

View File

@ -7,6 +7,7 @@ import TrackPlaylistIcon from '~/components/playlists/TrackPlaylistIcon.vue'
import onKeyboardShortcut from '~/composables/onKeyboardShortcut' import onKeyboardShortcut from '~/composables/onKeyboardShortcut'
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
import { useGettext } from 'vue3-gettext' import { useGettext } from 'vue3-gettext'
import { useMouse, useWindowSize } from '@vueuse/core'
import useQueue from '~/composables/audio/useQueue' import useQueue from '~/composables/audio/useQueue'
import usePlayer from '~/composables/audio/usePlayer' import usePlayer from '~/composables/audio/usePlayer'
@ -95,9 +96,12 @@ const switchTab = () => {
const progressBar = ref() const progressBar = ref()
const touchProgress = (event: MouseEvent) => { const touchProgress = (event: MouseEvent) => {
const time = ((event.clientX - (event.target as Element).getBoundingClientRect().left) / progressBar.value.offsetWidth) * duration.value const time = ((event.clientX - ((event.target as Element).closest('.progress')?.getBoundingClientRect().left ?? 0)) / progressBar.value.offsetWidth) * duration.value
currentTime.value = time currentTime.value = time
} }
const { x } = useMouse()
const { width: screenWidth } = useWindowSize()
</script> </script>
<template> <template>
@ -132,6 +136,10 @@ const touchProgress = (event: MouseEvent) => {
class="position bar" class="position bar"
:style="{ 'transform': `translateX(${progress - 100}%)` }" :style="{ 'transform': `translateX(${progress - 100}%)` }"
/> />
<div
class="seek bar"
:style="{ 'transform': `translateX(${x / screenWidth * 100 - 100}%)` }"
/>
</div> </div>
<div class="controls-row"> <div class="controls-row">
<div class="controls track-controls queue-not-focused desktop-and-up"> <div class="controls track-controls queue-not-focused desktop-and-up">

View File

@ -1,18 +0,0 @@
<script setup lang="ts">
interface Props {
component: unknown
index: number
dragClassHandler: (index: number) => string
}
defineProps<Props>()
</script>
<template>
<Component
:is="component"
:class="dragClassHandler(index)"
:index="index"
:data-index="index"
/>
</template>

View File

@ -189,7 +189,7 @@ defineExpose({
</div> </div>
</template> </template>
<style> <style lang="scss">
.drag-container { .drag-container {
position: relative; position: relative;
} }
@ -202,11 +202,19 @@ defineExpose({
.drop-before { .drop-before {
box-shadow: 0 -1px 0 var(--vibrant-color), box-shadow: 0 -1px 0 var(--vibrant-color),
inset 0 1px 0 var(--vibrant-color); inset 0 1px 0 var(--vibrant-color);
&:last-child {
box-shadow: inset 0 2px 0 var(--vibrant-color);
}
} }
.drop-after { .drop-after {
box-shadow: 0 1px 0 var(--vibrant-color), box-shadow: 0 1px 0 var(--vibrant-color),
inset 0 -1px 0 var(--vibrant-color); inset 0 -1px 0 var(--vibrant-color);
&:last-child {
box-shadow: inset 0 -2px 0 var(--vibrant-color);
}
} }
.drag-ghost { .drag-ghost {

View File

@ -49,13 +49,20 @@
.ui.progress .bar { .ui.progress .bar {
transition: none; transition: none;
width: 100%; width: 100%;
transform: scaleX(0); transform: translateX(-100%);
transform-origin: top left; transform-origin: top left;
will-change: transform; will-change: transform;
}
.ui.progress .buffer.bar {
position: absolute; position: absolute;
&.seek {
background: var(--player-color);
opacity: 0;
transition: opacity .2s ease;
mix-blend-mode: overlay;
}
}
.ui.progress:hover .bar.seek {
opacity: 0.4;
} }
@keyframes MOVE-BG { @keyframes MOVE-BG {

View File

@ -158,7 +158,7 @@
.ui.progress .bar { .ui.progress .bar {
transition: none; transition: none;
width: 100%; width: 100%;
transform: scaleX(0); transform: translateX(-100%);
transform-origin: top left; transform-origin: top left;
will-change: transform; will-change: transform;
} }