电子雨代码-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>
相关推荐
IT_陈寒几秒前
Vite项目build后路由404了?你可能漏了这个小配置
前端·人工智能·后端
lichenyang4537 分钟前
AI 聊天从纯文本到结构化卡片:SSE done 帧携带 card + 历史记录卡片恢复实战
前端
梦曦i43 分钟前
@meng-xi/vite-plugin v0.1.5:告别手动 import,精简工具层
前端
梦曦i1 小时前
Vite 0.1.6重磅更新:智能导入+路由安全
前端
gxf5203088069881 小时前
Flutter 裁剪图片
前端·app
ITMan彪叔2 小时前
赋能UE运行态编辑平台: 网络图片下载的插件改造与复盘
前端
RANxy2 小时前
🚀 Umi Max 项目从0到1:企业级 React 脚手架实战
前端·前端框架
拾年2752 小时前
深入理解 V8 引擎:从代码执行到垃圾回收的完整链路
前端·javascript·v8
Master_Azur2 小时前
javaScript进阶
前端
markfeng82 小时前
React入门教学
前端·react.js