添加背景网格组件并优化滚动条样式
This commit is contained in:
+8
-6
@@ -38,12 +38,6 @@ body {
|
|||||||
color: #000;
|
color: #000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 核心:点阵网格背景 */
|
|
||||||
.bg-dot-grid {
|
|
||||||
background-size: 24px 24px;
|
|
||||||
background-image: radial-gradient(circle, var(--grid-dot) 1px, transparent 1px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.no-scrollbar {
|
.no-scrollbar {
|
||||||
scrollbar-width: none;
|
scrollbar-width: none;
|
||||||
-ms-overflow-style: none;
|
-ms-overflow-style: none;
|
||||||
@@ -51,3 +45,11 @@ body {
|
|||||||
.no-scrollbar::-webkit-scrollbar {
|
.no-scrollbar::-webkit-scrollbar {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html, body {
|
||||||
|
scrollbar-width: none; /* Firefox */
|
||||||
|
-ms-overflow-style: none; /* IE and Edge */
|
||||||
|
}
|
||||||
|
html::-webkit-scrollbar, body::-webkit-scrollbar {
|
||||||
|
display: none; /* Chrome, Safari and Opera */
|
||||||
|
}
|
||||||
+3
-1
@@ -3,6 +3,7 @@ import localFont from "next/font/local";
|
|||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
import SmoothScroller from "@/components/dom/SmoothScroller";
|
import SmoothScroller from "@/components/dom/SmoothScroller";
|
||||||
import Header from "@/components/dom/Header";
|
import Header from "@/components/dom/Header";
|
||||||
|
import BackgroundGrid from "@/components/dom/BackgroundGrid";
|
||||||
|
|
||||||
const tiktokSans = localFont({
|
const tiktokSans = localFont({
|
||||||
src: "./fonts/TikTokSans.ttf",
|
src: "./fonts/TikTokSans.ttf",
|
||||||
@@ -34,7 +35,8 @@ export default function RootLayout({
|
|||||||
}>) {
|
}>) {
|
||||||
return (
|
return (
|
||||||
<html lang="en" className={`${tiktokSans.variable} ${geistMono.variable} ${departureMono.variable}`}>
|
<html lang="en" className={`${tiktokSans.variable} ${geistMono.variable} ${departureMono.variable}`}>
|
||||||
<body className="bg-dot-grid min-h-screen">
|
<body className="min-h-screen relative">
|
||||||
|
<BackgroundGrid />
|
||||||
<SmoothScroller />
|
<SmoothScroller />
|
||||||
<Header />
|
<Header />
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
export default function BackgroundGrid() {
|
||||||
|
const [size, setSize] = useState({ w: 375, h: 812 });
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const updateSize = () => {
|
||||||
|
setSize({ w: window.innerWidth, h: window.innerHeight });
|
||||||
|
};
|
||||||
|
updateSize();
|
||||||
|
window.addEventListener('resize', updateSize);
|
||||||
|
return () => window.removeEventListener('resize', updateSize);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const { w, h } = size;
|
||||||
|
|
||||||
|
// Calculate grid lines
|
||||||
|
// Responsive padding: lg is px-14 (56px), mobile is px-4 (16px)
|
||||||
|
const isDesktop = w >= 1024;
|
||||||
|
const paddingX = isDesktop ? 56 : 16;
|
||||||
|
const edgeOffset = paddingX + 0.5; // +0.5 for crisp SVG rendering
|
||||||
|
|
||||||
|
const cols = 3; // Left, Center, Right
|
||||||
|
const rows = Math.ceil(h / 450) + 1;
|
||||||
|
|
||||||
|
const vLines = Array.from({ length: cols }).map((_, i) => {
|
||||||
|
if (i === 0) return edgeOffset;
|
||||||
|
if (i === cols - 1) return w - edgeOffset;
|
||||||
|
return w / 2;
|
||||||
|
});
|
||||||
|
|
||||||
|
const hLines = Array.from({ length: rows }).map((_, i) => (i + 1) * 442);
|
||||||
|
|
||||||
|
// Generate paths
|
||||||
|
let vPath = '';
|
||||||
|
let hPath = '';
|
||||||
|
let crossPath = '';
|
||||||
|
|
||||||
|
const crossSize = 6; // 12px total width/height for the cross
|
||||||
|
|
||||||
|
vLines.forEach(x => {
|
||||||
|
hLines.forEach((y, i) => {
|
||||||
|
const startY = i === 0 ? 0 : hLines[i - 1] + 12;
|
||||||
|
const endY = y - 12;
|
||||||
|
vPath += `M${x} ${startY}V${endY} `;
|
||||||
|
|
||||||
|
crossPath += `M${x} ${y - crossSize}V${y + crossSize} `;
|
||||||
|
crossPath += `M${x - crossSize} ${y}H${x + crossSize} `;
|
||||||
|
});
|
||||||
|
const lastY = hLines[hLines.length - 1] + 12;
|
||||||
|
vPath += `M${x} ${lastY}V${h} `;
|
||||||
|
});
|
||||||
|
|
||||||
|
hLines.forEach(y => {
|
||||||
|
vLines.forEach((x, i) => {
|
||||||
|
const startX = i === 0 ? 0 : vLines[i - 1] + 12;
|
||||||
|
const endX = x - 12;
|
||||||
|
hPath += `M${startX} ${y}H${endX} `;
|
||||||
|
});
|
||||||
|
const lastX = vLines[vLines.length - 1] + 12;
|
||||||
|
hPath += `M${lastX} ${y}H${w} `;
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="z-20 fixed inset-0 w-full h-full pointer-events-none mix-blend-difference">
|
||||||
|
<svg viewBox={`0 0 ${w} ${h}`} className="block shape-rendering-crispEdges w-full h-full">
|
||||||
|
<path d={vPath} stroke="rgba(255, 255, 255, 0.1)" strokeWidth="1" fill="none" />
|
||||||
|
<path d={hPath} stroke="rgba(255, 255, 255, 0.1)" strokeWidth="1" fill="none" />
|
||||||
|
<path d={crossPath} stroke="#FFFFFF" strokeWidth="1" fill="none" opacity="0.4" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user