What is a waterfall Stream page layout?
Waterfall flow, also known as Waterfall flow layout. is a more popular Web page layout, visual representation of the uneven layout of multiple columns, as the page scroll down, this layout will continue to load the data block and attached to the current tail.
Look at the code below, with pure CSS3 to do see how the effect!
Html
<div id= "All" > <div class= "box" > <div class= "pic" > </div> </ div> <div class= "box" > <div class= "pic" > </div> </div> <div class= "box" > <div class= "pic" > </div> </div> <div class= "box" > <div class= "pic" > </div> </div> <div class= "box" > <div class= "pic" > </div> </div> <div class= "box" > <div class= "pic" > </div> </div> <div class= "box" > <div class= "pic" > </div> </div> <div class= "box" > <div class= "pic" > </div> </div> <div class= "box" > <div class= "pic" > > </div> <div class= "box" > <div class= "pic"> </div> </div> <div class=" box "> <div class=" pic "> </div> </div> <div class= "box" > <div class= "pic" > </div> </div> </div>
Here with a large box to install the whole content, small box box block content, pic box to install pictures. Look at the CSS code
Css
*{
margin:0;
padding:0;
}
#all {
/* key code
/-webkit-column-width:437px;
-moz-column-width:437px;
-o-column-width:437px;
-ms-column-width:437px;
/*-webkit-column-count:3;
-moz-column-count:3;
-o-column-count:3;
-ms-column-count:3;*/
/*-webkit-column-rule:2px dashed #F00;
-moz-column-rule:2px dashed #F00;
-o-column-rule:2px dashed #F00;
-ms-column-rule:2px dashed #F00; * *
/*-webkit-column-gap:5px;
-moz-column-gap:5px;
-o-column-gap:5px;
-ms-column-gap:5px;*/
}
. box{
padding:15px 0 0 15px;
}
. pic{
padding:10px;
border:1px solid #ccc;
border-radius:5px;
box-shadow:0 0 5px #ccc;
width:400px
}
. pic>img{
width:400px;
Height:auto;
}
The effect is coming out.
Visible CSS3 Although realized waterfall flow, but the painting wind looks strange, the left and right arrangement spacing is not flexible. Column width changes with the size of the browser window, the user experience is not good, the picture sorted in a vertical order, disrupting the picture display order, the picture load or rely on JavaScript to achieve. The only advantage is that you do not need to compute, the browser automatically calculates, just set the column width, high performance.
In order to get better results, so we still use the algorithm to achieve it, the following jquery code with CSS to achieve waterfall flow.
Css
*{
margin:0;
padding:0;
}
#all {
position:relative;
}
. box{
padding:15px 0 0 15px;
Float:left
}
. pic{
padding:10px;
border:1px solid #ccc;
border-radius:5px;
box-shadow:0 0 5px #ccc;
}
. pic>img{
width:400px;
Height:auto;
}
Jquery
$ (window). Load (function () {waterfall ();//var dataint={"data": [{"src": "cars/1.jpg"},{"src": "cars/2.jpg"},{"src": " Cars/3.jpg "},{" src: "Cars/4.jpg"}]}//$ (window). Scroll (function () {//if (checkscrollslide) {//$.each (Dataint.data, function (Key,value) {//var obox=$ ("<div>"). addclass ("box"). Appendto ($ ("#all"));//var opic=$ ("<div>").
AddClass ("Pic"). Appendto ($ (obox));
var oimg=$ ("div"); var w= $boxs. EQ (0). Outerwidth (); var Cols=math.floor ($ (win
Dow). Width ()/w);
$ (' #all '). Width (w*cols). CSS ("margin", "0 auto");
var harr=[]; $boxs. Each (function (index,value) {var h= $boxs. EQ (index). Outerheight (); if (index<cols) {harr[index]=h;} else{var minh=math.min.apply (Null,harr); var minhindex=$.inarray (Minh,harr);//Console.log (MinH); $ (value). css ({' Position ': ' absolute ', ' top ': minh+ ' px ', ' Left ': minhindex*w+ ' px '} harr[minhindex]+= $boxs. EQ (iNdex). Outerheight ();
}
}); //function Checkscrollslide () {//var $lastBox =$ ("#all >div"). Last ();//var lastboxdis= $lastBox. Offset (). Top+math
. Floor ($lastBox. Outerheight ()/2);
var scrolltop=$ (window). scrolltop ();
var documenth=$ (window). Height ();
Return (Lastboxdis<scrolltop+documenth) True:false;
//}
The effect is as follows
Obviously the effect is much better, the picture sort is according to the position of the picture calculate crosswise sort, the position is calculated, compare norm.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.