电子雨代码-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>
相关推荐
Mintopia3 分钟前
Three.js 自定义几何体:解锁 3D 世界的创造力
前端·javascript·three.js
Mintopia7 分钟前
计算机图形学碰撞检测:数字世界的 “防碰瓷” 秘籍
前端·javascript·计算机图形学
Hilaku9 分钟前
为什么说 CSS 是最被低估的编程语言?
前端·css
Hilaku17 分钟前
我用 Cursor 写了两个月代码,项目代码量不降反升,为什么?
前端·javascript·架构
哀木18 分钟前
识别手写数字,居然可以只靠前端?
前端
Dream耀21 分钟前
掌握Flex布局核心:项目属性深度指南
前端·css·html
绅士玖29 分钟前
从电影网站揭秘:前端开发中那些鲜为人知的黑科技与设计哲学
前端·javascript·css
_风满楼31 分钟前
如何优雅展示日历中的重叠日程?三步搞定复杂布局
前端·javascript·算法
CAD老兵31 分钟前
TypeScript 函数重载详解:原理、实践与最佳用法
前端