前端瀑布流效果

先看效果

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body style="background-color: #000;padding: 0; margin: 0;">
    <canvas id="canvas"></canvas>
</body>
    <script>
        let cvs = document.querySelector('canvas');
        let ctx = cvs.getContext('2d');
        function init() {
            cvs.width = window.innerWidth * devicePixelRatio;
            cvs.height = window.innerHeight * devicePixelRatio;
            console.log(cvs.width);
            console.log(cvs.height);
        }
        init()
        
        let fontsize = 20 * devicePixelRatio;
        ctx.fillStyle="#000"
        let columCount = Math.floor(cvs.width/fontsize);//获取列
        let charIndex = new Array(columCount).fill(0);

        function draw() {
            ctx.fillStyle='rgba(0,0,0,0.1)'
            ctx.fillRect(0,0,cvs.width,cvs.height)
            ctx.fillStyle='#6be445'
            ctx.textBaseline='top'
            for (let i = 0; i < columCount; i++) {
                let x = i *fontsize;
                let y = charIndex[i] *fontsize;
                ctx.fillText(getRandomText(),x,y)
                if(y>cvs.height && Math.random()>0.99){
                    charIndex[i] = 0;
                }else{
                    charIndex[i]++
                }
            }
        }
        draw()
        function getRandomText() {
            let str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            return str[Math.floor(Math.random()*str.length)]
        }
        
        setInterval(draw, 50);
    </script>
</html>
相关推荐
ZhengEnCi4 小时前
Q06-导航按钮高级拟态玻璃效果构建完全指南
前端·css
用户059540174469 小时前
Redis持久化踩坑实录:这个数据丢失Bug让我排查了6小时
前端·css
用户059540174461 天前
Redis记忆存储故障恢复测试踩坑实录:手动测试让我漏掉了2个一致性Bug
前端·css
用户059540174461 天前
用了3年Mock,才发现Redis记忆存储的测试一直漏掉了60%的边界场景
前端·css
用户059540174462 天前
用了6个月LangChain,才发现AI Agent的记忆存储一直有坑——写了23个Pytest用例才彻底修好
前端·css
用户059540174462 天前
把LLM记忆测试从手工脚本换成Pytest参数化,回归时间从2小时降到10分钟
前端·css
用户059540174463 天前
Redis缓存一致性踩坑实录:线上故障排查6小时,我用pytest+内存快照把它永久关进了笼子
前端·css
llllk4 天前
新手向逐段讲解
css
玄玄子5 天前
CSS 浮动引起父元素高度塌陷
前端·css
用户0926292831456 天前
CSS 代码调试总踩坑?Gemini 3.5 精准定位修复
css