电子雨代码-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>
相关推荐
Halo_tjn20 分钟前
基于封装的专项 知识点
java·前端·python·算法
m0_748229993 小时前
Vue2 vs Vue3:核心差异全解析
前端·javascript·vue.js
C澒3 小时前
前端监控系统的最佳实践
前端·安全·运维开发
xiaoxue..3 小时前
React 手写实现的 KeepAlive 组件
前端·javascript·react.js·面试
hhy_smile3 小时前
Class in Python
java·前端·python
小邓吖4 小时前
自己做了一个工具网站
前端·分布式·后端·中间件·架构·golang
南风知我意9574 小时前
【前端面试2】基础面试(杂项)
前端·面试·职场和发展
LJianK14 小时前
BUG: Uncaught Error: [DecimalError] Invalid argument: .0
前端
No Silver Bullet4 小时前
Nginx 内存不足对Web 应用的影响分析
运维·前端·nginx
一起养小猫5 小时前
Flutter for OpenHarmony 实战 表单处理与验证完整指南
android·开发语言·前端·javascript·flutter·harmonyos