电子雨代码-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>
相关推荐
木斯佳22 分钟前
鸿蒙开发入门指南:前端开发者快速掌握常用布局
前端·css
咕噜咪24 分钟前
OpenLayers 入门教程:从零开始学习Web地图开发
前端·学习
炽烈小老头28 分钟前
前端最最最基础的基础HTML基础
前端·html
小霖家的混江龙38 分钟前
仿淘宝 AI 推荐:用 Next.js 构建入门智能水果推荐 Demo
前端·人工智能·next.js
诚诚程程成43 分钟前
URL Query Editor 前端开发工具:方便调试页面URL参数 URL参数可视化
前端
CHU7290351 小时前
直播逛购新体验——直播商城APP前端功能详解
前端·小程序
Jackson__1 小时前
Agent Skill 和 MCP 到底有什么区别?很多人搞混了
前端·ai编程·mcp
new code Boy2 小时前
Vue2转Vue3速查表
前端·javascript·vue.js
紫_龙2 小时前
最新版vue3+TypeScript开发入门到实战教程之toRefs与toRef实用技巧
前端·javascript·typescript
大家的林语冰2 小时前
Vite 第 1 个 Rolldown 稳定版正式发布,前端构建又一波“工业革命“
前端·javascript·vite