电子雨代码-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>
相关推荐
林太白10 分钟前
rust17-部门管理模块
前端·后端·rust
_处女座程序员的日常10 分钟前
如何预览常见格式word、excel、ppt、图片等格式的文档
前端·javascript·word·excel·开源软件
明月与玄武13 分钟前
前端文件上传终极指南:从原理到架构实践!
前端·前端文件上传终极指南
布列瑟农的星空44 分钟前
后台类项目如何挖掘前端技术亮点
前端·面试
wangbing11251 小时前
layui窗口标题
前端·javascript·layui
qq_398586541 小时前
Utools插件实现Web Bluetooth
前端·javascript·electron·node·web·web bluetooth
李剑一2 小时前
mitt和bus有什么区别
前端·javascript·vue.js
VisuperviReborn2 小时前
React Native 与 iOS 原生通信:从理论到实践
前端·react native·前端框架
hashiqimiya2 小时前
html的input的required
java·前端·html
Mapmost2 小时前
WebGL三维模型标准(二)模型加载常见问题解决方案
前端