html 代码雨

3642 1
Spade_King 2022-10-11 10:24:26 | 显示全部楼层 |阅读模式
本帖最后由 Spade_King 于 2022-10-11 10:25 编辑

主要是熟悉画布的使用
有兴趣的可以自己复制代码到记事本,修改后缀为html
内容变量str可自己编辑

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Code</title>
    <style>
        body{
            margin: 0;
            overflow: hidden;
        }
    </style>
</head>

<body>
<canvas id="myCanvas"></canvas>
<script>
    const width = document.getElementById("myCanvas").width = screen.availWidth;
    const height = document.getElementById("myCanvas").height = screen.availHeight;
    const ctx = document.getElementById("myCanvas").getContext("2d");
    const arr = Array(Math.ceil(width / 9)).fill(0);
    const str = "ABCDEFGHIJKLMNOPQRS0123456789王爱罗:“{}|TUVWXYZ".split("");

    function rain() {
        ctx.fillStyle = "rgba(0,0,0,0.05)";
        ctx.fillRect(0, 0, width, height);
        ctx.fillStyle = "#0f0";
        arr.forEach(function (value, index) {
            ctx.fillText(str[Math.floor(Math.random() * str.length)], index * 10, value + 10);
            arr[index] = value >= height || value > 8888 * Math.random() ? 0 : value + 17;
        });
    }

    setInterval(rain, 20);
</script>
</body>
</html>
wangjun 2022-10-11 18:15:24 来自手机 | 显示全部楼层
好像有一个标签/没打
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Spade_King

初级红客

关注
  • 6
    主题
  • 0
    粉丝
  • 1
    关注
想学就会

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2026 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行