电子雨代码-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>
相关推荐
问道飞鱼17 分钟前
【Tauri框架学习】Tauri 与 React 前端集成:通信机制与交互原理详解
前端·学习·react.js·rust·通信
霍理迪21 分钟前
Vue列表过滤与排序
前端·javascript·vue.js
牛十二26 分钟前
智能体框架开发实战
运维·服务器·前端
鹅天帝27 分钟前
20230319网安学习日志——XSS漏洞
前端·学习·web安全·网络安全·xss
floret. 小花27 分钟前
Vue3 + Electron 知识点总结 · 2026-03-21
前端·面试·electron·学习笔记·vue3
蓝黑202029 分钟前
Vue的v-if和v-for放在同一个HTML元素里的坑
前端·javascript·vue.js
转角羊儿36 分钟前
精灵图案例
开发语言·前端·javascript
大雷神39 分钟前
HarmonyOS APP<玩转React>开源教程十八:课程详情页面
前端·react.js·开源·harmonyos
听风者一号44 分钟前
cssMoudle生成器
前端·javascript·json
霍理迪1 小时前
Vue—其他指令及自定义指令
前端·javascript·vue.js