电子雨代码-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>
相关推荐
We་ct22 分钟前
React 性能优化精讲
前端·javascript·react.js·性能优化·前端框架·html·浏览器
云动课堂32 分钟前
【运维实战】Nginx 高性能Web服务 · 一键自动化部署方案 (适配银河麒麟 V10 / openEuler / CentOS 7/8)
运维·前端·nginx
大前端helloworld2 小时前
AI全自动实现Flutter蓝牙自动连接
前端
GISer_Jing2 小时前
从入门到落地:前端开发者的AI Agent全栈学习路线
前端·人工智能·ai编程
计算机安禾2 小时前
【Linux从入门到精通】第47篇:SystemTap与eBPF——Linux内核观测的显微镜
java·linux·前端
技术钱3 小时前
OutputParser输出解析器
linux·服务器·前端·python
可达鸭小栈4 小时前
易语言实现CSS像素文字生成器:无需字体文件渲染汉字
前端·css
fox_lht4 小时前
DBeaver的LightGrid 类所有函数详细分析
前端
钛态4 小时前
前端TypeScript高级技巧:让你的代码更安全
前端·vue·react·web
光影少年4 小时前
前端在页面渲染优化和组件优化经验?
前端·vue.js·react.js·前端框架