• h5 jq实现瀑布流


    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <style>
        .box {
            position: relative;
            margin: 0 auto;
        }
        .item {
            position: absolute;
             200px;
            margin: 5px;
            border: 1px solid #ddd;
            transition: all 1s;
        }
        .item img {
             100%;
            height: auto;
        }
    </style>
    <body>
        <div class="box">
            <div class="item"><img
                    src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2241344963,3314667459&fm=26&gp=0.jpg" />
            </div>
            <div class="item"><img
                    src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2879759251,3409178712&fm=26&gp=0.jpg" />
            </div>
            <div class="item"><img
                    src="https://img-blog.csdn.net/2018071611132815?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxNDg1NDE0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" />
            </div>
            <div class="item"><img
                    src="https://img-blog.csdn.net/2018071611132815?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxNDg1NDE0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" />
            </div>
            <div class="item"><img
                    src="https://img-blog.csdn.net/2018071611132815?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxNDg1NDE0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" />
            </div>
        </div>
    </body>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <script>
        $(function () {
            init();
            $(window).on('resize', function () {//重新加载
                init();
            });
        })
        function init() {
            var boxWidth = $(".item").outerWidth(true);
            // 获取每个小盒子的宽度 包括margin、padding、border
            var cols = parseInt($(window).width() / boxWidth);
            // 获取列数
            var heightArr = [];
            for (var i = 0; i < cols; i++) {
                heightArr.push(0);
            };
            //遍历每一张图片
            $(".item").each(function (index, item) {
                var idx = 0;
                var minBoxHeight = heightArr[0];
                // 获取最小高度
                for (var i = 0; i < heightArr.length; i++) {
                    if (heightArr[i] < minBoxHeight) {
                        minBoxHeight = heightArr[i];
                        idx = i;
                        // 获取最小高度的索引
                    }
                };
                // 设置图片的样式
                $(item).css({
                    left: boxWidth * idx,
                    top: minBoxHeight
                });
                heightArr[idx] += $(item).outerHeight(true);
            });
        };
    </script>
    </html>
  • 相关阅读:
    vue学习简单入门
    Python3基础学习
    MySQL数据库索引详解
    使用nginx部署多个前端项目
    基于SpringBoot2.x和tkMapper快速搭建微服务项目脚手架工程
    安装篇-Linux安装maven3.5.2
    安装篇-安装maven3.6.1
    安装篇-安装Idea2019.3.3
    安装篇-jdk1.8安装
    【错误解决】Intellj(IDEA) warning no artifacts configured
  • 原文地址:https://www.cnblogs.com/mcll/p/11890459.html
Copyright © 2020-2023  润新知