电子雨代码-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>
相关推荐
风骏时光牛马12 小时前
Cube Sandbox部署问题及解决方法
前端
Bug-制造者12 小时前
深入理解 HTML5 Web Workers:提升网页性能的关键技术解析
前端·html·html5
Sylvia33.12 小时前
足球数据API接入实战:从认证到实时比分推送的完整指南
java·开发语言·前端·c++·python
_小郑有点困了12 小时前
学习Python基础语法及使用
前端·python·学习
LPieces12 小时前
【LPieces-UI】01-从零开始搭建 Vue3 组件库
前端
学习使我快乐0112 小时前
AI时代下,前端如何破局
前端·人工智能
yingyima13 小时前
Unix 时间戳转换实战:一次差点毁掉项目的低级错误
前端
盼兮13 小时前
用AI编程从零搭建一个响应式数据看板
前端·人工智能·数据可视化
Lan.W13 小时前
vue3-element-admin里新增mock接口一直没有生成,不生效
前端·javascript·vue.js·mock
小满zs13 小时前
Next.js部署(Vercel)
前端·next.js