Skip to content

Commit 0959876

Browse files
committed
feat(gradient): 添加渐变背景和动画效果
1 parent 03ab14c commit 0959876

File tree

4 files changed

+592
-4
lines changed

4 files changed

+592
-4
lines changed

src/index.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,34 @@
2121
}
2222

2323

24+
@layer utilities{
25+
.animation-delay-100 {
26+
animation-delay: 100ms;
27+
}
28+
.animation-delay-200 {
29+
animation-delay: 200ms;
30+
}
31+
.animation-delay-300 {
32+
animation-delay: 300ms;
33+
}
34+
}
35+
2436
a{
2537
grid-template-columns: repeat(2,1fr);
38+
}
39+
40+
.animation-fadeIn{
41+
opacity: 0;
42+
animation: fadeIn 0.5s ease forwards;
43+
}
44+
45+
@keyframes fadeIn{
46+
0%{
47+
opacity: 0;
48+
transform: translateY(30px);
49+
}
50+
100%{
51+
opacity: 1;
52+
transform: translateY(0);
53+
}
2654
}

src/layouts/default.tsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import { ProjectCard } from "@/components/ProjectCard";
33
import projectData from "@/data/projects/data.json";
44
import labData from "@/data/labs/data.json";
55
import { IconBrandX, IconBrandGithub, IconMail } from "@tabler/icons-react";
6+
import { Gradient } from "@/lib/Gradient.js";
7+
import { useEffect } from "react";
68

79
const Layout: React.FC = () => {
810
return (
911
<>
1012
<main className="flex flex-col gap-8 py-10 px-5 w-full max-w-screen-md mx-auto">
11-
<Bg />
13+
{/* <Bg /> */}
14+
<GradientBg />
1215
<MineInfos />
1316
<Projects />
1417
<Lab />
@@ -17,6 +20,25 @@ const Layout: React.FC = () => {
1720
)
1821
};
1922

23+
const GradientBg = () => {
24+
useEffect(() => {
25+
const gradient = new Gradient();
26+
gradient.initGradient('#gradient-canvas');
27+
}, []);
28+
const style: any = {
29+
"--gradient-color-1": "#043D5D",
30+
"--gradient-color-2": "#032E46",
31+
"--gradient-color-3": "#23B684",
32+
"--gradient-color-4": "#0F595E",
33+
};
34+
return (
35+
<div className="fixed w-full h-2/3 top-0 left-0 opacity-40 pointer-events-none">
36+
<span className="absolute w-full h-full top-0 left-0 bg-gradient-to-b from-transparent to-[#09090b]"></span>
37+
<canvas style={style} className="w-full h-full" id="gradient-canvas"></canvas>
38+
</div>
39+
)
40+
}
41+
2042
const Bg = () => {
2143
return (
2244
<div className="fixed w-[60vw] h-[60vw] left-1/4 -top-10 blur-2xl overflow-hidden">
@@ -28,7 +50,7 @@ const Bg = () => {
2850

2951
const MineInfos = () => {
3052
return (
31-
<div className="relative flex flex-col gap-8">
53+
<div className="animation-fadeIn !animation-delay-100 relative flex flex-col gap-8">
3254
<a target="_blank" href="https://github.com/oopserian" className="border border-zinc-50 block w-12 h-12 rounded-full overflow-hidden bg-gradient-to-t from-zinc-50 to-green-50">
3355
<img className="w-full h-full object-cover" src="/logo.webp" />
3456
</a>
@@ -54,7 +76,7 @@ const MineInfos = () => {
5476
const Projects = () => {
5577
const projectDataList = Object.values(projectData);
5678
return (
57-
<div className="flex flex-col gap-2.5">
79+
<div className="animation-fadeIn !animation-delay-200 flex flex-col gap-2.5">
5880
<h2 className="text-xl font-bold">Projects</h2>
5981
<div className="grid grid-cols-[repeat(auto-fill,minmax(250px,1fr))] gap-2.5">
6082
{
@@ -70,7 +92,7 @@ const Projects = () => {
7092
const Lab = () => {
7193
const labDataList = Object.values(labData);
7294
return (
73-
<div className="flex flex-col gap-2.5">
95+
<div className="animation-fadeIn !animation-delay-300 flex flex-col gap-2.5">
7496
<h2 className="text-xl font-bold">Lab</h2>
7597
<div className="grid grid-cols-[repeat(auto-fill,minmax(250px,1fr))] gap-2.5">
7698
{

src/lib/Gradient.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// 为Gradient.js创建类型声明
2+
export class Gradient {
3+
constructor(...args: any[]);
4+
initGradient(canvasSelector: string): void;
5+
connect(): Promise<void>;
6+
disconnect(): void;
7+
initMaterial(): void;
8+
initMesh(): void;
9+
shouldSkipFrame(timestamp: number): boolean;
10+
updateFrequency(frequency: number): void;
11+
toggleColor(index: number): void;
12+
showGradientLegend(): void;
13+
hideGradientLegend(): void;
14+
init(): void;
15+
waitForCssVars(): Promise<any>;
16+
initGradientColors(): void;
17+
}

0 commit comments

Comments
 (0)