电子雨代码-html

电子雨代码

动画效果展示

代码

javascript 复制代码
<!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 / 10)).fill(0);

        const str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".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 + 10;

            });

        }

        setInterval(rain, 30);

    </script>

</body>

</html>
相关推荐
福兮说38 分钟前
JSON 格式正确,数据就可靠吗?我用一份自编配置检查类型与空值
java·前端·json
程序员老赵2 小时前
Docker 部署青龙面板:轻松搭建定时任务管理平台
前端·docker·开源
Swot2 小时前
Asciidoctor 公式数字下标错位问题:原因分析与解决方案
前端
Swot2 小时前
leo-editor 中将 Markdown 内容转成 asciidoc 格式
前端
狒狒AI3 小时前
Remotion / GSAP+Three / HyperFrames / Skia 四栈实测:代码渲染知识视频的选栈方法(附开源技能)
前端·人工智能·aigc
修炼的dance3 小时前
浏览器里导出H.265,8.5秒和55.5秒差在硬件
前端
补码缩写3 小时前
WebCodecs选编码器,探测之后还要验解码和播放
前端
大文说跨境3 小时前
亚马逊多账号管理浏览器怎么选?云登/紫鸟/AdsPower 对比
java·前端·自动化
hunter_0763 小时前
iOS 首页复杂嵌套滚动技术方案:头部固定 + 网格滚动 + Tab 吸顶 + 每 Tab 独立下拉刷新
前端
CoderYanger3 小时前
Java EE 进阶:4.Spring Web MVC 入门(第一弹)
java·开发语言·前端·spring·面试·java-ee·mvc