Jquery implements waterfall stream and data interaction with php

Source: Internet
Author: User
Jquery implements waterfall stream and interacts with php to implement data. js previously implemented a waterfall stream, and jquery also implemented

Main ideas:

1. display about 20 images first, so that the scroll bar appears on the interface.

2. set the parent id of the displayed image to relative positioning and float positioning.

3. use the displayed image as a fold to render it as a waterfall stream.

4. when you scroll the scroll bar, determine whether to load the image.

5. sort the newly loaded images into the waterfall stream again.

Important:

1. determine when to load the new image

2. implement waterfall stream sorting

How can I determine which part of the image to load? click the limit button in the background.

Okay. the code is as follows:

1. show some images first

// Implement the waterfall stream display image public function photo () {$ id = M ("Cate")-> field ("id ") -> where ("name = 'Album expression'")-> select (); $ this-> image_list = M ("Blog")-> field ("content, summary ")-> limit (10)-> order (" time desc ")-> where (" cid = {$ id [0] ['id']} ") -> select (); $ this-> length = 10; // 10 images are displayed at the beginning. $ this-> cur_position = 'Album expression '; $ this-> id = $ id [0] ['id']; $ this-> display ();}

2 front-end code:

 

3 foreground style:

    
     


4. key js code:

$ (Function () {waterfall (); // load the image $ (window ). scroll (function () {if (checkscrollside () {var offset = $ ("input [name = offset]"). val (); var length = $ ("input [name = length]"). val (); var justice = $ ("input [name = justic]"). val (); if (justice = offset) {return false;} else {$ ("input [name = justic]"). val (offset) ;}$. post (// sort the waterfall stream by adding new elements each time "/Index/Show/more_photo", {offset: offset, length: length}, function (data) {if (data) {$ (data ). each (function (index, value) {$ li = $ ("
  • "). AddClass ("wf-cld "). appendTo ("# wf-main"); $ (""). attr ({"src": value. summary, "title": value.titleapps).css ({"width": "200px", "height": "auto "}). appendTo ($ li) ;}); $ ("input [name = offset]"). val (parseInt (offset) + 10); console. log ($ ("# wf-main> li "). length); // make sure that the height of the scroll bar remains unchanged var scroll_top = $ (window ). scrollTop (); waterfall (); $ (window ). scrollTop (scroll_top) ;}}, "json") ;}}) ;}); // let the image collapse and arrange function waterfall () {var $ par_main = $ ("# wf-main"); // parent element var $ child_main = $ ("# wf-main> li "); // subelement var par_width = $ par_main.width (); // Obtain the width of the parent element var child_width = $ child_main.eq (0 ). width (); // Obtain the width of the child element var num_col = Math. floor (par_width/child_width); // how many columns are displayed in a row var col_arr = []; // The height of all elements in a column after adding multiple values: col_arr.length = 0; $ child_main.each (function (index, value) {if (index <num_col) {col_arr [index] = $ (value ). height ();} else {var minH = Math. min. apply (null, col_arr); // The minimum value of minH var min_index in the array pinHArr = $. inArray (minH, col_arr ); // obtain the minimum index value // the height of the smallest element in the array + the height of the new block + 15 spaces away from col_arr [min_index] + = $ child_main.eq (index ). height () + 15; ((value0000.css ({// set the position of the element to display: "absolute", top: minH + 15, left: $ child_main.eq (min_index ). position (). left}); var maxH = Math. max. apply (null, col_arr); $ par_main.height (maxH); // change parent element height }});} // whether to add a scroll bar. when the top of the last image is half the height of the last image, it serves as the dividing line function checkscrollside () {var $ child_main = $ ("# wf-main> li"); var trigger_heigth = $ child_main.last (). get (0 ). offsetTop + $ child_main.height ()/2; // The height of the scroll bar var scroll_top = $ (window ). scrollTop (); // Obtain the page width var docu_width = $ (document ). width (); return (trigger_heigth
    5. reload the background code of the new image every time:

    // According to ajax, some images are displayed each time. public function more_photo () {$ offset = $ _ POST ['offset']; $ length = $ _ POST ['length']; $ id = M ("Cate")-> field ("id")-> where ("name = 'Album expression'")-> select (); $ image_list = M ("Blog")-> field ("content, summary, title")-> limit ($ offset, $ length)-> order ("time desc ") -> where ("cid = {$ id [0] ['id']}")-> select (); exit (json_encode ($ image_list ));}


    Well, this is the end:

    By the way, the show shows the results:

    The actual address is on my blog:

    Http://buyingfeiblog.sinaapp.com/

    The code is in progress, so stay tuned!

  • 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.