电子雨代码-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>
相关推荐
砺能1 分钟前
谷歌浏览器中出现部分字体乱码问题
前端
To_OC8 分钟前
绕开层层 props 搬运:我把 useContext 和自定义 Hook 跑通了
前端·react.js·前端框架
北凉温华9 分钟前
Vue3 可视化打印设计插件|拖拽生成票据/标签打印模板(开源体验版)
前端
程序员黑豆19 分钟前
Java变量详解:从入门到精通
java·前端·ai编程
andr_gale1 小时前
02_uniapp自定义上凸效果的底部TabBar
前端·javascript·uni-app·移动端
一心只读圣贤书1 小时前
AI 驱动前端测试实战:从需求文档到 Playwright 自动化用例
前端·人工智能
拖孩1 小时前
用 AI 重解千年观音灵签,做了一个微信小程序,每天摇一摇,命运给你回应
前端·后端·微信小程序
難釋懷1 小时前
Nginx日志
前端·网络·nginx
Web极客码2 小时前
用 Python 搭建工具调用 Agent 的调试过程
java·服务器·前端
2401_881828322 小时前
简易文本处理网页工具|AI 通识课第三次作业
前端·javascript·html