Skip to content

Commit fe9b3d2

Browse files
committed
refactor: remove scroll-based parallax effect and reduce star count to 200
1 parent d6650bb commit fe9b3d2

File tree

2 files changed

+2
-20
lines changed

2 files changed

+2
-20
lines changed

src/app/page.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function IndexPage() {
1212
<div className="relative">
1313
{/* Main Background */}
1414
<div className="absolute inset-0 z-0">
15-
<StarryBackground starCount={240} />
15+
<StarryBackground starCount={200} />
1616
</div>
1717

1818

src/components/StarryBackground.jsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import React, { useEffect, useState, useRef } from 'react';
55
const StarryBackground = ({ starCount = 240 }) => {
66
const [stars, setStars] = useState([]);
77
const [mousePosition, setMousePosition] = useState({ x: 0, y: 0 });
8-
const [scrollOffset, setScrollOffset] = useState(0);
98
const [isMobile, setIsMobile] = useState(false);
109
const containerRef = useRef(null);
1110

@@ -62,15 +61,6 @@ const StarryBackground = ({ starCount = 240 }) => {
6261
return () => window.removeEventListener('mousemove', handleMouseMove);
6362
}, []);
6463

65-
// 监听页面滚动
66-
useEffect(() => {
67-
const handleScroll = () => {
68-
setScrollOffset(window.scrollY);
69-
};
70-
71-
window.addEventListener('scroll', handleScroll);
72-
return () => window.removeEventListener('scroll', handleScroll);
73-
}, []);
7464

7565
// 计算星星的位移
7666
const getStarTransform = (star) => {
@@ -81,18 +71,10 @@ const StarryBackground = ({ starCount = 240 }) => {
8171
3: 4, // 最下层,位移最大
8272
};
8373

84-
// 不同层级的滚动偏移系数(轻微的视差效果)
85-
const scrollLayerMultipliers = {
86-
1: 0.001, // 最上层,几乎不动
87-
2: 0.002, // 中间层,轻微偏移
88-
3: 0.003, // 最下层,稍多偏移
89-
};
90-
9174
const mouseMultiplier = mouseLayerMultipliers[star.layer];
92-
const scrollMultiplier = scrollLayerMultipliers[star.layer];
9375

9476
const offsetX = -mousePosition.x * mouseMultiplier;
95-
const offsetY = -mousePosition.y * mouseMultiplier + scrollOffset * scrollMultiplier;
77+
const offsetY = -mousePosition.y * mouseMultiplier;
9678

9779
return `translate(${offsetX}px, ${offsetY}px)`;
9880
};

0 commit comments

Comments
 (0)