电子雨代码-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>
相关推荐
a1117761 小时前
星球主题个人主页(纯HTML 开源)
前端·html
空条jo太郎2 小时前
echarts图表联动
前端
webkubor2 小时前
2026 年 把网页交互的主控权拿回前端手中 🚀
前端·javascript·人工智能
凯里欧文4272 小时前
极简版前端版本检测方案
前端·webpack
Desirediscipline2 小时前
#include<limits>#include <string>#include <sstream>#include <iomanip>
java·开发语言·前端·javascript·算法
青青家的小灰灰2 小时前
深入解析 React 中的 useCallback:原理、场景与最佳实践
前端·react.js
HelloReader2 小时前
Nuxt 4.2 + Tauri 2 接入指南把 Vue 元框架“静态化”后装进桌面/移动端
前端
SuperEugene2 小时前
手把手写几种常用工具函数:深拷贝、去重、扁平化
前端·javascript·面试
大时光2 小时前
疯狂点赞效果
前端
小岛前端2 小时前
前端真神器!RD280U 让我写码效率暴涨!
前端·程序员