<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> Waterfall Flow </title>
<style type= "Text/css" >
*{margin:0;padding:0}
#container {width:90%;margin:0 Auto;}
. topic {width:200px; border:1px solid #ccc; border-radius:5px; padding:5px; box-shadow:5px 5px 5px #ccc; float:left; margi n:5px;}
. topic img {width:200px;}
</style>
<script type= "Text/javascript" src= "Js/jquery-1.12.4.js" ></script>
<script type= "Text/javascript" >
$ (function () {
var conwidth=$ ("#container"). Innerwidth (),
towidth=$ (". Topic"). EQ (0). Outerwidth (),
Cols=math.floor (Conwidth/towidth),
spacing= (Conwidth-towidth*cols)/(cols+1);
var html= "";
Console.log (cols);
A box that holds cols columns into a contaner container
for (Var i=0;i<cols;i++) {
html+= "<div style= ' display:inline-block;vertical-align:top;width:" +towidth+ "Px;margin-left:" +spacing+ "PX; ' ></div> "
}
var $conCols =$ (HTML). AppendTo ("#container");
Traverse the loaded picture
$ (". Topic"). each (function (index,element) {
var cur=index%cols;
$conCols. EQ (cur). append (Element);
});
Add a picture to a page dynamically
Html= "";
for (Var i=16;i<56;i++) {
html+= "<div class= ' topic ' ></div>";
}
$ (HTML). Each (function (index,element) {
var cur=index%cols;
$conCols. EQ (cur). append (Element);
});
});
</script>
<body>
<div id= "Container" >
<div class= "topic" ></div>
<div class= "topic" ></div>
<div class= "topic" ></div>
<div class= "topic" ></div>
<div class= "topic" ></div>
<div class= "topic" ></div>
<div class= "topic" ></div>
<div class= "topic" ></div>
<div class= "topic" ></div>
<div class= "topic" ></div>
<div class= "topic" ></div>
<div class= "topic" ></div>
<div class= "topic" ></div>
<div class= "topic" ></div>
<div class= "topic" ></div>
</div>
</body>
Waterfall Flow with jquery (Mode 1-Fixed width and number of columns, add images sequentially)