每移动一个 20px 网格,就会点亮一个新方块:随机从 6 色里取一个颜色,随机从 11 个符号里取一个字符,30% 概率是空格。方块从 scale(0) 弹到 scale(1),停留 100–400ms 后缩回去。
总共只有 10 个方块在轮转复用 —— 所以拖尾最长不会超过 10 段。这是原站的做法,不是每帧新建元素。
colors[Math.floor(Math.random() * colors.length)]。// 网格吸附:只有当网格坐标变了才点亮,避免高频抖动 gx = grid * Math.floor(clientX / grid) gy = grid * Math.floor(clientY / grid) // 轮转复用 10 个方块 idx = (idx + 1) % pool tiles[idx] = { x: gx, y: gy, active: true, color: colors[random], text: random() < .3 ? " " : chars[random] } // 到点失活,CSS 负责缩回去 setTimeout(() => tiles[idx].active = false, 100 + 300 * Math.random())
transform: translate(x, y),容器 position: fixed,所以直接吃视口坐标。