小编Vas*_*rov的帖子

如何让矩阵背景渲染在页面内容后面?

我想在我的 Web 应用程序中使用这个很酷的矩阵背景,但它涵盖了我的所有元素(div、标题、段落等)。

我尝试用 css 解决这个问题,但它不起作用。所以现在我陷入困境并请求你的帮助。

这是我来自 CodePen 的代码:

const canvas = document.getElementById('canv');
const ctx = canvas.getContext('2d');

const w = canvas.width = document.body.offsetWidth;
const h = canvas.height = document.body.offsetHeight;
const cols = Math.floor(w / 20) + 1;
const ypos = Array(cols).fill(0);

ctx.fillStyle = '#000';
ctx.fillRect(0, 0, w, h);

function matrix () {
  ctx.fillStyle = '#0001';
  ctx.fillRect(0, 0, w, h);

  ctx.fillStyle = '#0f0';
  ctx.font = '15pt monospace';

  ypos.forEach((y, ind) => {
    const text = String.fromCharCode(Math.random() * 128);
    const x = ind …
Run Code Online (Sandbox Code Playgroud)

html javascript css codepen

3
推荐指数
1
解决办法
2612
查看次数

标签 统计

codepen ×1

css ×1

html ×1

javascript ×1