This commit is contained in:
2026-04-25 03:13:14 +09:00
parent e561f9d1e0
commit f238e618ee
2 changed files with 27 additions and 15 deletions
+25 -13
View File
@@ -3,27 +3,39 @@
const header = document.querySelector('header');
if (!header) return;
const configs = [
{ blur: 2, from: '0%', to: '20%' },
{ blur: 3, from: '20%', to: '40%' },
{ blur: 5, from: '40%', to: '60%' },
{ blur: 8, from: '60%', to: '80%' },
{ blur: 13, from: '80%', to: '100%' },
];
const LAYERS = 8;
const MAX_BLUR = 16;
const configs = Array.from({ length: LAYERS }, (_, i) => {
const t = i / (LAYERS - 1);
const blur = MAX_BLUR * Math.pow(t, 2);
const from = (i / LAYERS) * 100;
const to = ((i + 1) / LAYERS) * 100;
const mid = (from + to) / 2;
return { blur, from, to, mid };
});
const root = document.createElement('div');
root.className = 'header-blur';
root.setAttribute('aria-hidden', 'true');
let parent = root;
for (const cfg of configs) {
const layer = document.createElement('div');
layer.className = 'blur-layer';
layer.style.setProperty('--blur', cfg.blur + 'px');
layer.style.setProperty('--from', cfg.from);
layer.style.setProperty('--to', cfg.to);
parent.appendChild(layer);
parent = layer;
layer.style.setProperty('--blur', cfg.blur.toFixed(2) + 'px');
const fadeHalf = (cfg.to - cfg.from);
const a = Math.max(0, cfg.from - fadeHalf);
const b = cfg.from;
const c = cfg.to;
const d = Math.min(100, cfg.to + fadeHalf);
layer.style.setProperty(
'--mask',
`linear-gradient(to top,
transparent ${a}%,
black ${b}%,
black ${c}%,
transparent ${d}%)`
);
root.appendChild(layer);
}
header.prepend(root);