impr: use custom progress bar
This commit is contained in:
6 files changed
+60
-19
No files matched your search
@@ -24,7 +24,7 @@
|
||||
<svelte:element
|
||||
this={settings.expandImages ? 'button' : 'a'}
|
||||
href={postLink(post)}
|
||||
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900"
|
||||
class="container mx-auto z-10 rounded-xl max-h-[60vh] relative overflow-hidden bg-slate-100 dark:bg-zinc-900 cursor-pointer"
|
||||
data-sveltekit-preload-data="off"
|
||||
aria-label={post.name}
|
||||
onclick={() => showImage(bestImageURL(post, false, -1, null))}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
size="16"
|
||||
micro
|
||||
class={[
|
||||
open && 'rotate-90',
|
||||
open && 'rotate-180',
|
||||
'transition-transform duration-300 ease-out',
|
||||
]}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<script lang="ts">
|
||||
let progress = $state(0)
|
||||
|
||||
let increaseInterval: number = -1
|
||||
let startTimeout: number = -1
|
||||
let stopTimeout: number = -1
|
||||
|
||||
export function start() {
|
||||
clearTimeout(stopTimeout)
|
||||
progress = 0
|
||||
startTimeout = setTimeout(() => {
|
||||
progress = 1
|
||||
// schedule a setInterval and run the code immediately
|
||||
;(function i() {
|
||||
if (progress < 100 && progress > 0)
|
||||
// slowly get closer and closer to 90% -- 100% doesnt look very good to be stuck on
|
||||
progress += (100 - (progress - 10)) / 4
|
||||
increaseInterval = setInterval(i, 400) as unknown as number
|
||||
})()
|
||||
}, 100) as unknown as number
|
||||
}
|
||||
|
||||
export function stop() {
|
||||
if (progress != 0) progress = 100
|
||||
// reset progress to 0 after bar disappears
|
||||
setTimeout(() => (progress = 0), 500)
|
||||
clearInterval(increaseInterval)
|
||||
clearTimeout(startTimeout)
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
class={[
|
||||
'fixed top-0 left-0 h-px z-[400] bg-primary-900 dark:bg-primary-100',
|
||||
progress == 100 && 'opacity-0',
|
||||
progress > 0 && 'use-transition',
|
||||
]}
|
||||
style="width: {progress}%;"
|
||||
id="progress-bar"
|
||||
></div>
|
||||
|
||||
<style>
|
||||
#progress-bar.use-transition {
|
||||
transition:
|
||||
width 0.7s cubic-bezier(0, 0, 0.22, 0.76),
|
||||
opacity 0.5s linear;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user