纯CSS特效-矩阵数字雨动画

首先看下效果图

效果图

代码:

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>纯CSS特效-矩阵数字雨动画</title>
    <!--适应移动端-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--css样式-->
    <style>
        body {
            margin: 0;
            overflow: hidden;
        }
    </style>
    <!--引用jquery库-->
    <script src="https://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
</head>

<body>
    <canvas id="q" width="100%" height="100%">
        <script>const s = window.screen;
            const w = (q.width = s.width);
            const h = (q.height = s.height);
            const ctx = q.getContext("2d");

            const p = Array(Math.floor(w / 10) + 1).fill(0);

            const random = (items) => items[Math.floor(Math.random() * items.length)];

            const hex = "023456789ABCDEFGHKLMNOPQRSTUVWXYZ*****".split("");

            setInterval(() => {
                ctx.fillStyle = "rgba(0,0,0,.05)";
                ctx.fillRect(0, 0, w, h);
                ctx.fillStyle = "#0f0";
                p.map((v, i) => {
                    ctx.fillText(random(hex), i * 10, v);
                    p[i] = v >= h || v > 50 + 10000 * Math.random() ? 0 : v + 10;
                });
            }, 1000 / 30);
        </script>
    </canvas>
</body>

</html>
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容