添加背景网格组件并优化滚动条样式

This commit is contained in:
2026-08-31 20:39:50 +08:00
parent 37173cfbeb
commit 77b928c442
3 changed files with 86 additions and 7 deletions
+75
View File
@@ -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>
);
}