电子雨代码-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>
相关推荐
阿珊和她的猫3 分钟前
React 路由:构建单页面应用的导航系统
前端·react.js·状态模式
Amumu1213814 分钟前
Vue脚手架(二)
前端·javascript·vue.js
花间相见20 分钟前
【LangChain】—— Prompt、Model、Chain与多模型执行链
前端·langchain·prompt
lichenyang4531 小时前
从零开始构建 React 文档系统 - 完整实现指南
前端·javascript·react.js
比特森林探险记1 小时前
Hooks、状态管理
前端·javascript·react.js
landonVM1 小时前
Linux 上搭建 Web 服务器
linux·服务器·前端
css趣多多1 小时前
路由全局守卫
前端
AI视觉网奇2 小时前
huggingface-cli 安装笔记2026
前端·笔记
比特森林探险记2 小时前
组件通信 与 ⏳ 生命周期
前端·javascript·vue.js
2301_792580002 小时前
xuepso
java·服务器·前端