电子雨代码-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>
相关推荐
晴殇i几秒前
深入理解MessageChannel:JS双向通信的高效解决方案
前端·javascript·程序员
毕设十刻2 分钟前
基于Vue的民宿管理系统st4rf(程序 + 源码 + 数据库 + 调试部署 + 开发环境配置),配套论文文档字数达万字以上,文末可获取,系统界面展示置于文末
前端·数据库·vue.js
kkkAloha5 分钟前
倒计时 | setInterval
前端·javascript·vue.js
云轩奕鹤13 分钟前
智析单词书 - AI 驱动的深度英语词汇学习平台
前端·ai·产品·思维
逆光如雪22 分钟前
控制台快速查看自己的log,提高开发效率
前端
用户479492835691522 分钟前
年薪百万的 React 功底怎么“装进”AI?Vercel 的这个 Skill 给了标准答案
前端·aigc·ai编程
jason_yang23 分钟前
这5年在掘金的感想
前端·javascript·vue.js
一人の梅雨23 分钟前
亚马逊SP-API商品评论接口实战:情感分析+商业洞察挖掘的差异化方案
运维·前端·数据库
掘金一周26 分钟前
Dart 官方再解释为什么放弃了宏编程,并转向优化 build_runner ?| 掘金一周 1.15
前端
魔术师卡颂38 分钟前
提问量暴跌 80% ,Stack Overflow 却赚翻了?
前端·后端·ai编程