Skip to content

Commit acfdf00

Browse files
authored
Player particles and bug fixes (#20)
* fix iOS thumb having a bg * fixes light mode rocket image * adds particle effect to thumb * fix iOS thumb having a bg * fixes light mode rocket image * adds particle effect to thumb * simplified and more effective no pointer events class * fix when at 0 * dots hid within the track with subtle margin, instead of behind ship
1 parent d925ea5 commit acfdf00

3 files changed

Lines changed: 96 additions & 0 deletions

File tree

src/components/Player.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,24 @@ export default function Player() {
2424
const percentage =
2525
(audioPlayer.current.currentTime / audioPlayer.current.duration) * 100;
2626
setProgress(percentage);
27+
2728
const slider = document.querySelector('.slider');
29+
const particles = document.querySelector('.ship-particles');
30+
2831
if (slider) {
2932
(slider as HTMLElement).style.setProperty(
3033
'--seek-before-width',
3134
`${percentage}%`
3235
);
3336
}
37+
38+
if (particles && slider) {
39+
const pxOffset = slider.clientWidth * (percentage / 100);
40+
(particles as HTMLElement).style.setProperty(
41+
'--seek-particles-left',
42+
`${pxOffset - 10}px` // -5 to put the dots into the track
43+
);
44+
}
3445
}
3546
progressRef.current = requestAnimationFrame(whilePlaying);
3647
}

src/components/player/Slider/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ export default function Slider({ audioPlayer, progress }: Props) {
5454
}
5555
}}
5656
/>
57+
<div className={"ship-particles absolute h-full -top-[1px] grid place-items-center place-content-center pointer-events-none"}>
58+
<div className="w-1 h-1 rounded-full row-start-1 col-start-1"></div>
59+
<div className="w-1 h-1 rounded-full row-start-1 col-start-1"></div>
60+
<div className="w-1 h-1 rounded-full row-start-1 col-start-1"></div>
61+
<div className="w-1 h-1 rounded-full row-start-1 col-start-1"></div>
62+
<div className="w-1 h-1 rounded-full row-start-1 col-start-1"></div>
63+
</div>
5764
<span class="hidden text-nowrap text-sm tabular-nums md:inline-block">
5865
{formatTime(currentTime, totalTime)} / {formatTime(totalTime)}
5966
</span>

src/components/player/Slider/styles.css

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
@apply relative -mt-[5px] box-content h-4 w-4 cursor-pointer appearance-none bg-contain bg-no-repeat transition-opacity duration-300 lg:opacity-0;
2020
background-image: url('/images/rocket-dark.svg');
2121
background-position: center center;
22+
box-shadow: none;
23+
background-color: #0000;
2224
}
2325
&::-moz-range-track {
2426
@apply h-1.5 w-full cursor-pointer border-none bg-gray-200 outline-none dark:bg-gray-700;
@@ -35,6 +37,15 @@
3537
background-position: center center;
3638
}
3739

40+
@media (prefers-color-scheme: light) {
41+
&::-webkit-slider-thumb {
42+
background-image: url('/images/rocket-light.svg');
43+
}
44+
&::-moz-range-thumb {
45+
background-image: url('/images/rocket-light.svg');
46+
}
47+
}
48+
3849
&:hover {
3950
&::-webkit-slider-thumb {
4051
@apply opacity-100;
@@ -44,4 +55,71 @@
4455
@apply opacity-100;
4556
}
4657
}
58+
59+
&:not(:hover) ~ .ship-particles {
60+
display: none;
61+
}
62+
}
63+
64+
.ship-particles {
65+
left: max(0px, var(--seek-particles-left));
66+
67+
> div {
68+
animation:
69+
ship-particles-x 1s ease infinite,
70+
ship-particles-y 1s ease infinite;
71+
animation-composition: add;
72+
background-color: #B0ECFF;
73+
opacity: 0;
74+
75+
@media (prefers-color-scheme: light) {
76+
background-color: #906BFF;
77+
}
78+
79+
&:nth-child(1) {
80+
animation-delay: 0.4s;
81+
--y-offset: -10px;
82+
--x-offset: -20px;
83+
}
84+
&:nth-child(2) {
85+
animation-delay: 0.8s;
86+
--y-offset: -20px;
87+
--x-offset: -15px;
88+
}
89+
&:nth-child(3) {
90+
animation-delay: 0.1s;
91+
--y-offset: 15px;
92+
--x-offset: -25px;
93+
}
94+
&:nth-child(4) {
95+
animation-delay: 0.3s;
96+
--y-offset: 25px;
97+
--x-offset: -10px;
98+
}
99+
&:nth-child(5) {
100+
animation-delay: 0.7s;
101+
--y-offset: 17px;
102+
--x-offset: -15px;
103+
}
104+
}
105+
}
106+
107+
@keyframes ship-particles-x {
108+
0% {
109+
opacity: 1;
110+
transform: translateX(0) scale(1);
111+
}
112+
100% {
113+
opacity: 0;
114+
transform: translateX(var(--x-offset)) scale(.25) translateY(var(--y-offset));
115+
}
116+
}
117+
118+
@keyframes ship-particles-y {
119+
0%, 15% {
120+
transform: translateY(0);
121+
}
122+
100% {
123+
transform: translateY(var(--y-offset));
124+
}
47125
}

0 commit comments

Comments
 (0)