电子雨代码-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>
相关推荐
掘金安东尼9 分钟前
⏰前端周刊第 454 期(2026年2月16日-2月22日)
前端·javascript·面试
掘金安东尼22 分钟前
⏰前端周刊第 453 期(2026年2月9日-2月15日)
前端·javascript·面试
Amumu1213826 分钟前
CSS进阶导读
前端·css
anyup29 分钟前
uniapp开发的鸿蒙应用上架后,竟然月入4000+
前端·vue.js·harmonyos
无尽的沉默33 分钟前
使用Thymeleaf配置国际化页面(语言切换)
前端·spring boot
代码老中医1 小时前
接手老项目的一个月,我重构了那个2000行的“祖传”React组件
前端
用户83040713057011 小时前
路由传参刷新丢失问题:三种解决方案与最佳实践
前端
从文处安1 小时前
「前端何去何从」高效提示词(prompts):前端开发者的AI协作指南
前端·aigc
大时光1 小时前
gsap--《pink老师vivo官网实现》
前端
www_stdio1 小时前
全栈项目第五天:构建现代企业级 React 应用:从工程化到移动端实战的全链路指南
前端·react.js·typescript