Skip to content

Commit d1500f5

Browse files
committed
feat: star fall
1 parent 2903060 commit d1500f5

2 files changed

Lines changed: 65 additions & 20 deletions

File tree

src/components/stateless/Meteors/index.jsx

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,72 @@
11
import React from 'react'
2-
import clsx from 'clsx'
2+
import { motion } from 'framer-motion'
33

4-
import styles from './index.module.less'
4+
const Meteors = ({ starCount = 50, primaryColor = '#ffffff', className = '' }) => {
5+
const stars = Array.from({ length: starCount }, (_, i) => {
6+
const starTailLength = Math.random() * 2.5 + 5
7+
const topOffset = Math.random() * 100
8+
const fallDuration = Math.random() * 6 + 6
9+
const fallDelay = Math.random() * 10
10+
11+
return {
12+
id: i,
13+
topOffset,
14+
fallDuration,
15+
fallDelay,
16+
}
17+
})
518

6-
const Meteors = ({ number, className }) => {
7-
const meteors = new Array(number || 20).fill(true)
819
return (
9-
<>
10-
{meteors.map((el, idx) => (
11-
<span
12-
key={'meteor' + idx}
13-
className={clsx(
14-
`${styles['animate-meteor-effect']} absolute top-1/2 left-1/2 h-0.5 w-0.5 rotate-[215deg] rounded-[9999px] bg-slate-500 shadow-[0_0_0_1px_#ffffff10]`,
15-
"before:absolute before:top-1/2 before:h-[1px] before:w-[50px] before:-translate-y-[50%] before:transform before:bg-linear-to-r before:from-[#64748b] before:to-transparent before:content-['']",
16-
className
17-
)}
20+
<div
21+
className={`pointer-events-none absolute inset-0 h-full w-full -rotate-45 ${className}`}
22+
style={{
23+
perspective: '1000px',
24+
transformStyle: 'preserve-3d',
25+
}}
26+
>
27+
{stars.map((star) => (
28+
<motion.div
29+
key={star.id}
30+
className={`absolute h-[2px] rounded-full bg-gradient-to-r from-current to-transparent drop-shadow-[0_0_6px_currentColor]`}
1831
style={{
19-
top: 0,
20-
left: Math.floor(Math.random() * (400 - -400) + -400) + 'px',
21-
animationDelay: Math.random() * (0.8 - 0.2) + 0.2 + 's',
22-
animationDuration: Math.floor(Math.random() * (10 - 2) + 2) + 's',
32+
top: `${star.topOffset}vh`,
33+
width: '6em',
34+
color: primaryColor,
35+
willChange: 'transform',
36+
}}
37+
initial={{ x: '104em' }}
38+
animate={{ x: '-30em' }}
39+
transition={{
40+
duration: star.fallDuration,
41+
delay: star.fallDelay,
42+
repeat: Infinity,
43+
ease: 'linear',
44+
repeatType: 'loop',
2345
}}
24-
></span>
46+
>
47+
<div className="relative h-full w-full">
48+
<div
49+
className={`rounded-inherit animate-blink absolute top-0 left-[calc(-1em)] h-full w-[1em] bg-gradient-to-r from-transparent via-current to-transparent`}
50+
style={{
51+
willChange: 'transform, opacity',
52+
}}
53+
/>
54+
<div
55+
className={`rounded-inherit animate-blink absolute top-0 left-[calc(-1em)] h-full w-[1em] rotate-45 bg-gradient-to-r from-transparent via-current to-transparent`}
56+
style={{
57+
willChange: 'transform, opacity',
58+
}}
59+
/>
60+
<div
61+
className={`rounded-inherit animate-blink absolute top-0 left-[calc(-1em)] h-full w-[1em] -rotate-45 bg-gradient-to-r from-transparent via-current to-transparent`}
62+
style={{
63+
willChange: 'transform, opacity',
64+
}}
65+
/>
66+
</div>
67+
</motion.div>
2568
))}
26-
</>
69+
</div>
2770
)
2871
}
2972

src/pages/home/index.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ const Home = () => {
400400
overflow: 'hidden',
401401
}}
402402
>
403-
<Meteors number={40} />
403+
<Meteors starCount={30} primaryColor="#6366f1" className="opacity-30" />
404+
<Meteors starCount={25} primaryColor="#818cf8" className="opacity-50" />
405+
<Meteors starCount={20} primaryColor="#ffffff" className="opacity-70" />
404406
</section>
405407
<section
406408
style={{

0 commit comments

Comments
 (0)