/* 金钻客栈 · 加载动画(2026-10-06 重做) --------------------------------------------------------------------------- 像素钻石一块一块从上面落下来、从底往上垒成形(像 MC 里堆方块)→ 一道白光扫过钻石 →「金钻客栈」逐字弹出 → 底下一条光谱色进度条跟着页面真实加载走 → 整块幕布往上收起,露出页面。 · 只在这个标签页第一次打开网站时放(sessionStorage 记一下),之后站内换页不再放; · 系统设置了「减少动效」就完全不放(页面里那段内联脚本直接把幕布删掉); · 最少放 1.25 秒(垒完 + 白光扫过;太短一闪而过很怪),页面 3 秒还没加载完也照样收起,绝不卡人。 */ (function () { 'use strict'; var boot = document.getElementById('jzBoot'); if (!boot) return; var root = document.documentElement; var cv = boot.querySelector('canvas'), ctx = cv.getContext('2d'), bar = boot.querySelector('.jz-boot-bar i'); var name = boot.querySelector('.jz-boot-name'); var N = 14, CELL = cv.width / N, T0 = performance.now(), MIN = 1250, MAX = 3000, done = false, ready = false; var blocks = []; /* 把每个字拆开,好一个个弹出来 */ name.innerHTML = name.textContent.split('').map(function (c, i) { return '' + c + ''; }).join(''); /* 钻石原图是 14×14 的像素画:按格子中心取色,得到要垒的方块 */ var src = new Image(); src.onload = function () { var t = document.createElement('canvas'); t.width = t.height = N; var tc = t.getContext('2d'); tc.imageSmoothingEnabled = false; tc.drawImage(src, 0, 0, N, N); var d = tc.getImageData(0, 0, N, N).data; for (var y = 0; y < N; y++) for (var x = 0; x < N; x++) { var k = (y * N + x) * 4; if (d[k + 3] < 128) continue; /* 落下的先后:从底往上一层层垒,同一层里左右随机一点 */ var order = (N - 1 - y) + Math.random() * 0.9; blocks.push({ x: x, y: y, c: 'rgb(' + d[k] + ',' + d[k + 1] + ',' + d[k + 2] + ')', t: order }); } var maxT = 0; blocks.forEach(function (b) { if (b.t > maxT) maxT = b.t; }); blocks.forEach(function (b) { b.t = b.t / maxT; }); // 0..1 requestAnimationFrame(frame); }; src.src = 'assets/gem.webp'; var BUILD = 620, FALL = 260; // 整颗垒完 620ms,每块落 260ms function frame(now) { var el = now - T0; ctx.clearRect(0, 0, cv.width, cv.height); var built = true; for (var i = 0; i < blocks.length; i++) { var b = blocks[i], start = b.t * BUILD, k = (el - start) / FALL; if (k <= 0) { built = false; continue; } if (k < 1) built = false; k = Math.min(1, k); var e = 1 - Math.pow(1 - k, 3); // 落地减速 var y = (b.y - (1 - e) * (b.y + 3)) * CELL; ctx.globalAlpha = Math.min(1, k * 2.2); ctx.fillStyle = b.c; ctx.fillRect(b.x * CELL, y, CELL, CELL); /* 每块顶上一道亮边、底下一道暗边:方块感 */ ctx.globalAlpha *= 0.28; ctx.fillStyle = '#fff'; ctx.fillRect(b.x * CELL, y, CELL, 2); ctx.fillStyle = '#000'; ctx.fillRect(b.x * CELL, y + CELL - 2, CELL, 2); } ctx.globalAlpha = 1; /* 垒完以后一道白光斜着扫过钻石 */ var sw = (el - BUILD - FALL) / 520; if (sw > 0 && sw < 1) { ctx.save(); ctx.globalCompositeOperation = 'source-atop'; var gx = -cv.width * 0.6 + sw * cv.width * 2.2; var g = ctx.createLinearGradient(gx, 0, gx + cv.width * 0.5, cv.height); g.addColorStop(0, 'rgba(255,255,255,0)'); g.addColorStop(0.5, 'rgba(255,255,255,.85)'); g.addColorStop(1, 'rgba(255,255,255,0)'); ctx.fillStyle = g; ctx.fillRect(0, 0, cv.width, cv.height); ctx.restore(); } if (built && !boot.classList.contains('built')) boot.classList.add('built'); // 字开始弹出 /* 进度条:一半看时间(让动画走完),一半看页面真加载完没有 */ var p = Math.min(1, el / (BUILD + FALL + 300)) * (ready ? 1 : 0.82); bar.style.transform = 'scaleX(' + Math.max(p, parseFloat(bar.dataset.p || 0)).toFixed(3) + ')'; bar.dataset.p = p; if (boot.isConnected) requestAnimationFrame(frame); } function finish() { if (done) return; var el = performance.now() - T0; if (el < MIN) { setTimeout(finish, MIN - el); return; } done = true; bar.style.transform = 'scaleX(1)'; try { sessionStorage.setItem('jz-boot', '1'); } catch (e) {} setTimeout(function () { boot.classList.add('leave'); root.classList.remove('booting'); root.classList.add('booted'); setTimeout(function () { boot.remove(); }, 700); }, 160); } function onReady() { ready = true; finish(); } if (document.readyState === 'complete') onReady(); else addEventListener('load', onReady, { once: true }); setTimeout(function () { ready = true; finish(); }, MAX); /* 点一下就跳过 */ boot.addEventListener('click', function () { ready = true; T0 -= MIN; finish(); }); })();