Waterfall Flow with jquery (Mode 1-Fixed width and number of columns, add images sequentially)

Source: Internet
Author: User

<! 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.