Skip to content

Commit 12f97b5

Browse files
committed
feat: star background
1 parent 3f5f60c commit 12f97b5

3 files changed

Lines changed: 103 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React, { useEffect, useState } from 'react'
2+
import styles from './index.module.less'
3+
// 生成随机阴影值的函数
4+
const generateBoxShadow = (n) => {
5+
let shadowValues = []
6+
for (let i = 0; i < n; i++) {
7+
const randomX = Math.floor(Math.random() * 2000)
8+
const randomY = Math.floor(Math.random() * 2000)
9+
shadowValues.push(`${randomX}px ${randomY}px #333`)
10+
}
11+
return shadowValues.join(', ')
12+
}
13+
const StarBack = () => {
14+
const [smallShadows] = useState(generateBoxShadow(1400))
15+
const [mediumShadows] = useState(generateBoxShadow(400))
16+
const [bigShadows] = useState(generateBoxShadow(200))
17+
return (
18+
<section className="absolute top-0 left-0">
19+
<section className={styles.stars} style={{ '--box-shadow': smallShadows }}></section>
20+
<section className={styles.medium} style={{ '--box-shadow': mediumShadows }}></section>
21+
<section className={styles.big} style={{ '--box-shadow': bigShadows }}></section>
22+
</section>
23+
)
24+
}
25+
26+
export default StarBack
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
.stars {
2+
--box-shadow: 0 0 10px 1px rgb(255 255 255 / 50%);
3+
4+
width: 1px;
5+
height: 1px;
6+
border-radius: 100%;
7+
background: transparent;
8+
box-shadow: var(--box-shadow);
9+
animation: anim-star 50s linear infinite;
10+
11+
&::after {
12+
content: ' ';
13+
position: absolute;
14+
top: 2000px;
15+
width: 1px;
16+
height: 1px;
17+
border-radius: 100%;
18+
box-shadow: var(--box-shadow);
19+
background: transparent;
20+
}
21+
}
22+
23+
.medium {
24+
--box-shadow: 0 0 10px 1px rgb(255 255 255 / 50%);
25+
26+
width: 2px;
27+
height: 2px;
28+
border-radius: 100%;
29+
background: transparent;
30+
box-shadow: var(--box-shadow);
31+
animation: anim-star 150s linear infinite;
32+
33+
&::after {
34+
content: ' ';
35+
position: absolute;
36+
top: 2000px;
37+
width: 2px;
38+
height: 2px;
39+
border-radius: 100%;
40+
box-shadow: var(--box-shadow);
41+
background: transparent;
42+
}
43+
}
44+
45+
.big {
46+
--box-shadow: 0 0 10px 1px rgb(255 255 255 / 50%);
47+
48+
width: 3px;
49+
height: 3px;
50+
border-radius: 100%;
51+
background: transparent;
52+
box-shadow: var(--box-shadow);
53+
animation: anim-star 30s linear infinite;
54+
55+
&::after {
56+
content: '*';
57+
position: absolute;
58+
top: 2000px;
59+
width: 3px;
60+
height: 3px;
61+
border-radius: 100%;
62+
box-shadow: var(--box-shadow);
63+
background: transparent;
64+
}
65+
}
66+
67+
@keyframes anim-star {
68+
from {
69+
transform: translateY(-2000px);
70+
}
71+
72+
to {
73+
transform: translateY(0);
74+
}
75+
}

src/pages/demo/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import AnimationTabs from '@stateless/AnimationTabs'
55
import LogoSlider from '@stateless/LogoSlider'
66
import FloatingIcon, { SocialIcon } from '@stateless/FloatingIcon'
77
import Footer from '@stateless/Footer'
8+
import StarBack from '@stateless/StarBackground'
89

910
import StickyCard from '@stateless/StickyCard'
1011
import SpringPng from '@assets/images/spring.png'
@@ -85,6 +86,7 @@ const tabs = [
8586
const ProDemo = () => {
8687
return (
8788
<FixTabPanel>
89+
<StarBack />
8890
<StickyCard cards={[...Array.from({ length: 4 }, () => ({ id: Math.random() }))]} />
8991
<div className="relative w-full overflow-hidden bg-[#0a192f]">
9092
<div className="absolute top-0 right-0 h-full w-1/2">

0 commit comments

Comments
 (0)