电子雨代码-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>
相关推荐
_Eleven3 小时前
Tailwind CSS vs UnoCSS 深度对比
前端
NEXT064 小时前
TCP 与 UDP 核心差异及面试高分指南
前端·网络协议·面试
qq_24218863324 小时前
HTML 全屏烟花网页
前端·html
码云数智-大飞4 小时前
前端性能优化全链路实战:从加载速度到渲染效率的极致提速方案
前端·性能优化
锅包一切4 小时前
【蓝桥杯JavaScript基础入门】一、JavaScript基础
开发语言·前端·javascript·蓝桥杯
NEXT064 小时前
HTTP 协议演进史:从 1.0 到 2.0
前端·网络协议·面试
anOnion5 小时前
构建无障碍组件之Accordion Pattern
html·设计·交互设计
好学且牛逼的马5 小时前
从“混沌初开”到“有序统一”:Java集合框架发展历程与核心知识点详解
前端·数据库·python
嵌入式×边缘AI:打怪升级日志5 小时前
编写Bootloader实现下载功能
java·前端·网络
恋猫de小郭6 小时前
Flutter 设计包解耦新进展,material_ui 和 cupertino_ui 发布预告
android·前端·flutter