电子雨代码-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>
相关推荐
米欧几秒前
取消当前正在进行的所有接口请求
前端·javascript·axios
浪里行舟5 分钟前
告别“拼接”,迈入“原生”:文心5.0如何用「原生全模态」重塑AI天花板?
前端·javascript·后端
OpenTiny社区5 分钟前
救命!这个低代码工具太香了 ——TinyEngine 物料自动导入上手
前端·低代码·github
努力学前端Hang7 分钟前
移动端跨平台开发深度解析:UniApp、Taro、Flutter 与 React Native 对比
前端·javascript·react native·react.js
前端九哥18 分钟前
🚫循环里写return,浏览器当场沉默!
前端·javascript
亲爱的马哥25 分钟前
填鸭表单!开箱即用的开源问卷调查系统!
java·前端·低代码·产品经理
米诺zuo34 分钟前
nextjs文件路由、路由组
前端·next.js
加个鸡腿儿35 分钟前
锚点跳转-附带CSS样式 & 阻止页面刷新技术方案
前端·javascript·css
程序猿_极客1 小时前
【期末网页设计作业】HTML+CSS+JS 美食分享主题网站设计与实现(附源码)
javascript·css·html
dragon7251 小时前
FutureProvider会刷新两次的问题研究
前端·flutter