欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用js實現(xiàn)瀑布流效果

 更新時間:2021年09月17日 08:17:39   作者:那年風(fēng)吹雪正  
這篇文章主要為大家詳細介紹了使用js實現(xiàn)瀑布流效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了js實現(xiàn)瀑布流效果的具體代碼,供大家參考,具體內(nèi)容如下

源碼:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
 
        .box {
            width: 70px;
            float: left;
            margin-left: 4px;
            border-top: 1px solid #000;
        }
 
        ul,
        ol,
        li {
            list-style-type: none;
        }
 
        li {
            width: 70px;
            display: block;
            text-align: center;
        }
     
    </style>
</head>
 
<body>
    <ul class="box"></ul>
    <ul class="box"></ul>
    <ul class="box"></ul>
    <ul class="box"></ul>
 
    <button onclick="reloadPage()">刷新頁面</button>
</body>
 
</html>
<script>
    var boxs = document.querySelectorAll(".box");
    //創(chuàng)建最小值
    var min = 0;
    //創(chuàng)建顏色數(shù)組
    var colour = ["red", "yellow", "orange", "blue", "purple", "green","#cdee","#feda","ccc","#eda","#639","#33f","#f38","#ca0"]
    for (j = 1; j <= 50; j++) {
        var lis = document.createElement("li");//創(chuàng)建帶數(shù)字的li
        lis.innerHTML = j;
        lis.style.height = Math.random() * 40 + 30 + "px";//獲取隨機高度,最小高度為30px
        lis.style.backgroundColor = colour[parseInt(Math.random() * colour.length-1)];//獲取隨機顏色
        for (var i = 0; i < boxs.length; i++) {
            console.log(boxs[i].clientHeight);
            // offsetHeight獲得元素高度的 數(shù)字
            if (boxs[i].offsetHeight < boxs[min].offsetHeight) {
                min = i;//獲取高度最小數(shù)組元素的序號
            }
        }
        boxs[min].appendChild(lis)//把li添加到最短ol里
 
    }
 
    function reloadPage() {
        location.reload();//刷新
    }
 
</script>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論