电子雨代码-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>
相关推荐
锋行天下6 小时前
公司内网部署大模型的探索之路
前端·人工智能·后端
1024肥宅7 小时前
手写 EventEmitter:深入理解发布订阅模式
前端·javascript·eventbus
海市公约8 小时前
HTML网页开发从入门到精通:从标签到表单的完整指南
前端·ide·vscode·程序人生·架构·前端框架·html
行云流水6268 小时前
前端树形结构实现勾选,半勾选,取消勾选。
前端·算法
diudiu_339 小时前
web漏洞--认证缺陷
java·前端·网络
阿珊和她的猫9 小时前
<video>` 和 `<audio>` 标签的常用属性解析
前端
LSL666_9 小时前
4 jQuery、JavaScript 作用域、闭包与 DOM 事件绑定
前端·javascript·html
yinuo10 小时前
前端跨页面通讯终极指南⑤:window.name 用法全解析
前端
小飞侠在吗10 小时前
vue computed 和 watch
前端·javascript·vue.js
yinuo10 小时前
前端跨页面通讯终极指南④:MessageChannel 用法全解析
前端