|
1 | 1 | <script lang="ts"> |
2 | | - import { rect } from '$lib/actions'; |
3 | | - import { clamp } from '$lib/utils/clamp'; |
4 | | - import { onMount } from 'svelte'; |
5 | | - import { writable } from 'svelte/store'; |
6 | | -
|
7 | | - export let percentage = 0; |
8 | | - let easedPercentage = 0; |
9 | | -
|
10 | | - const elRect = writable<DOMRect | null>(null); |
11 | | - $: y = $elRect ? clamp(0, easedPercentage, 1) * $elRect.height : 0; |
12 | | -
|
13 | | - onMount(() => { |
14 | | - let frame: number | null = null; |
15 | | - const ease = () => { |
16 | | - easedPercentage += (percentage - easedPercentage); |
17 | | - frame = window.requestAnimationFrame(ease); |
18 | | - }; |
19 | | - ease(); |
20 | | -
|
21 | | - return () => { |
22 | | - frame && window.cancelAnimationFrame(frame); |
23 | | - }; |
24 | | - }); |
| 2 | + import { rect } from '$lib/actions'; |
| 3 | + import { clamp } from '$lib/utils/clamp'; |
| 4 | + import { onMount } from 'svelte'; |
| 5 | + import { writable } from 'svelte/store'; |
| 6 | +
|
| 7 | + export let percentage = 0; |
| 8 | + let easedPercentage = 0; |
| 9 | +
|
| 10 | + const elRect = writable<DOMRect | null>(null); |
| 11 | + $: y = $elRect ? clamp(0, easedPercentage, 1) * $elRect.height : 0; |
| 12 | +
|
| 13 | + onMount(() => { |
| 14 | + let frame: number | null = null; |
| 15 | + const ease = () => { |
| 16 | + easedPercentage += percentage - easedPercentage; |
| 17 | + frame = window.requestAnimationFrame(ease); |
| 18 | + }; |
| 19 | + ease(); |
| 20 | +
|
| 21 | + return () => { |
| 22 | + frame && window.cancelAnimationFrame(frame); |
| 23 | + }; |
| 24 | + }); |
25 | 25 | </script> |
26 | 26 |
|
27 | 27 | <div |
28 | | - class="scroll-indicator" |
29 | | - use:rect={elRect} |
30 | | - style:--y={`${y}px`} |
31 | | - style:--percentage={`${easedPercentage * 100}%`} |
| 28 | + class="scroll-indicator" |
| 29 | + use:rect={elRect} |
| 30 | + style:--y={`${y}px`} |
| 31 | + style:--percentage={`${easedPercentage * 100}%`} |
32 | 32 | > |
33 | | - <div class="cursor" /> |
| 33 | + <div class="aw-dot" /> |
34 | 34 | </div> |
35 | 35 |
|
36 | 36 | <style lang="scss"> |
37 | | - .scroll-indicator { |
38 | | - position: relative; |
39 | | -
|
40 | | - width: 1px; |
41 | | - flex-shrink: 0; |
42 | | - height: 100%; |
43 | | - background: linear-gradient( |
44 | | - to bottom, |
45 | | - hsl(var(--aw-color-accent)) 0%, |
46 | | - hsl(var(--aw-color-greyscale-700)) var(--percentage), |
47 | | - hsl(var(--aw-color-greyscale-700)) 100% |
48 | | - ); |
49 | | - border-radius: 100%; |
50 | | -
|
51 | | - .cursor { |
52 | | - border-radius: 16px; |
53 | | - border: 0.5px solid rgba(255, 255, 255, 0.16); |
54 | | - background: linear-gradient( |
55 | | - 138deg, |
56 | | - rgba(255, 255, 255, 0.13) 9.61%, |
57 | | - rgba(255, 255, 255, 0) 105.41% |
58 | | - ); |
59 | | - backdrop-filter: blur(100px); |
60 | | -
|
61 | | - width: 16px; |
62 | | - height: 16px; |
63 | | -
|
64 | | - position: absolute; |
65 | | - left: 50%; |
66 | | - translate: -50% var(--y, 0); |
67 | | - top: -8px; |
68 | | -
|
69 | | - &::after { |
70 | | - content: ''; |
71 | | - background-color: white; |
72 | | - border-radius: 100%; |
73 | | - width: 4px; |
74 | | - height: 4px; |
75 | | - position: absolute; |
76 | | - left: 50%; |
77 | | - top: 50%; |
78 | | - translate: -50% -50%; |
79 | | - } |
80 | | - } |
81 | | - } |
| 37 | + .scroll-indicator { |
| 38 | + position: relative; |
| 39 | +
|
| 40 | + width: 1px; |
| 41 | + flex-shrink: 0; |
| 42 | + height: 100%; |
| 43 | + background: linear-gradient( |
| 44 | + to bottom, |
| 45 | + hsl(var(--aw-color-accent)) 0%, |
| 46 | + hsl(var(--aw-color-greyscale-700)) var(--percentage), |
| 47 | + hsl(var(--aw-color-greyscale-700)) 100% |
| 48 | + ); |
| 49 | + border-radius: 100%; |
| 50 | + } |
| 51 | +
|
| 52 | + .aw-dot { |
| 53 | + position: absolute; |
| 54 | + left: 50%; |
| 55 | + translate: -50% var(--y, 0); |
| 56 | + top: -8px; |
| 57 | + } |
82 | 58 | </style> |
0 commit comments