Many people want to do the effect of Waterfall Stream. here we will tell you how to use it on the official website. first, download the jquery. masonry. min. js plug-in of Waterfall Stream. the URL is http://masonry.desandro.com/index.html.
Many people want to do the effect of Waterfall Stream. here we will tell you how to use it on the official website. first, download the jquery. masonry. min. js plug-in of Waterfall Stream. the URL is http://masonry.desandro.com/index.html.
Process:
1. During page initialization, the plug-in is called for a layout;
2. when you drag the scroll bar to the bottom, load the data once with ajax and display it in typographical form.
3. Repeat 2 until no data exists.
Html code:
-
-
-
-
- Insert title here
-
-
- Body {margin: 40px auto; width: 800px; font-size: 12px; color: #666 ;}
- . Item {
- Border: 1px solid # D4D4D4;
- Color: red;
- Margin: 0 10px 10px 0;
- Padding: 10px;
- Position: relative;
- Width: 200px;
- }
- . Loading-wrap {
- Bottom: 50px;
- Width: 100%;
- Height: 52px;
- Text-align: center;
- Display: none;
- }
- . Loading {
- Padding: 10px 10px 10px 52px;
- Height: 32px;
- Line-height: 28px;
- Color: # FFF;
- Font-size: 20px;
- Border-radius: 5px;
- Background: 10px center rgba (0, 0,. 7 );
- }
- . Footer {
- Border: 2px solid # D4D4D4;
- }
-
-
-
-
-
-
-
-
-
-
-
-
- Waterfall flow down
-
-
-
-
-
-
- Loading... please wait...
-
-
-
- I am the footer
-
-
- // Used to convert the unix timestamp
- Function unix_to_datetime (unix)
- {
- Var now = new Date (parseInt (unix) * 1000 );
- Return now. toLocaleString (). replace (/year | month/g, "-"). replace (/day/g ,"");
- }
- $ (Function (){
- // Execute the waterfall stream during page initialization
- Var $ container = $ ('# INER ');
- $ Container. masonry ({
- ItemSelector: '. item ',
- IsAnimated: true
- });
- // You can drag the scroll bar to load data once ajax reaches the bottom.
- Var loading = $ ("# loading"). data ("on", false); // you can add an attribute on to the loading div to determine whether to execute an ajax request.
- $ (Window). scroll (function (){
- If (loading. data ("on") return;
- If ($ (document ). scrollTop ()> $ (document ). height ()-$ (window ). height ()-$ ('. footer '). height () {// drag the page to the bottom
- // Load more data
- Loading. data ("on", true). fadeIn (); // here, set on to true to block subsequent ajax requests
-
- // Obtain The Last id
- Var lastid = $ ('. last_id: last'). val ();
- $. Get (
- "GetMore", // page to jump
- {Lastid: lastid}, // pass the value
- Function (data ){
- // Get the data, and add the data to the page using JS later
- Var getdata = data. data;
- Var html = "";
- If ($. isArray (getdata )){
- $. Each (data. data, function (I, item ){
- Html + =" The waterfall flow down again";
- });
- Var $ newElems = emerge (html).css ({opacity: 0}). appendTo ($ container );
- $ NewElems. imagesLoaded (function (){
- $ NewElems. animate ({opacity: 1 });
- $ Container. masonry ('append', $ newElems, true );
- });
- // Once the request is completed, set on to false. you can perform the next request.
- Loading. data ("on", false );
- }
- Loading. fadeOut ();
- },
- "Json"
- );
- }
- });
- });
-
-
-
Action code
- // Initialize the data
- Public function lists (){
- $ Data = D ('info')-> order ('Id desc')-> limit (10)-> select ();
- $ This-> assign ('data', $ data );
- $ This-> display ();
- }
- // Obtain the data of a request
- Public function getMore (){
- // Obtain The Last id
- If (! Emptyempty ($ _ GET ['lastid']) $ map ['id'] = array ('Lt ', $ _ GET ['lastid']);
- $ Data = D ('info')-> where ($ map)-> order ('Id desc')-> limit (10)-> select ();
- $ This-> ajaxReturn ($ data );
- }
Note:You can determine whether the window is scrolled to the bottom of the page to load the data once using ajax. if you do not process the data, the request will be made many times at once. Therefore, you must use conditions to limit it.
I used to assign a value to an element $ ("# loading "). data ("on", true); during the request, if the value is true, the request is not continued, and the value is false after the page request is complete.