ThinkPHP implements Waterfall Stream

Source: Internet
Author: User
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:

  1.  
  2.  
  3. Insert title here 
  4.  
  5. Body {margin: 40px auto; width: 800px; font-size: 12px; color: #666 ;}
  6. . Item {
  7. Border: 1px solid # D4D4D4;
  8. Color: red;
  9. Margin: 0 10px 10px 0;
  10. Padding: 10px;
  11. Position: relative;
  12. Width: 200px;
  13. }
  14. . Loading-wrap {
  15. Bottom: 50px;
  16. Width: 100%;
  17. Height: 52px;
  18. Text-align: center;
  19. Display: none;
  20. }
  21. . Loading {
  22. Padding: 10px 10px 10px 52px;
  23. Height: 32px;
  24. Line-height: 28px;
  25. Color: # FFF;
  26. Font-size: 20px;
  27. Border-radius: 5px;
  28. Background: 10px center rgba (0, 0,. 7 );
  29. }
  30. . Footer {
  31. Border: 2px solid # D4D4D4;
  32. }
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. Waterfall flow down 
  42.  
  43.  
  44.  
  45.  
  46.  
  47. Loading... please wait... 
  48.  
  49.  
  50.  
  51. I am the footer  
  52.  
  53. // Used to convert the unix timestamp
  54. Function unix_to_datetime (unix)
  55. {
  56. Var now = new Date (parseInt (unix) * 1000 );
  57. Return now. toLocaleString (). replace (/year | month/g, "-"). replace (/day/g ,"");
  58. }
  59. $ (Function (){
  60. // Execute the waterfall stream during page initialization
  61. Var $ container = $ ('# INER ');
  62. $ Container. masonry ({
  63. ItemSelector: '. item ',
  64. IsAnimated: true
  65. });
  66. // You can drag the scroll bar to load data once ajax reaches the bottom.
  67. Var loading = $ ("# loading"). data ("on", false); // you can add an attribute on to the loading div to determine whether to execute an ajax request.
  68. $ (Window). scroll (function (){
  69. If (loading. data ("on") return;
  70. If ($ (document ). scrollTop ()> $ (document ). height ()-$ (window ). height ()-$ ('. footer '). height () {// drag the page to the bottom
  71. // Load more data
  72. Loading. data ("on", true). fadeIn (); // here, set on to true to block subsequent ajax requests
  73.  
  74. // Obtain The Last id
  75. Var lastid = $ ('. last_id: last'). val ();
  76. $. Get (
  77. "GetMore", // page to jump
  78. {Lastid: lastid}, // pass the value
  79. Function (data ){
  80. // Get the data, and add the data to the page using JS later
  81. Var getdata = data. data;
  82. Var html = "";
  83. If ($. isArray (getdata )){
  84. $. Each (data. data, function (I, item ){
  85. Html + =" The waterfall flow down again";
  86. });
  87. Var $ newElems = emerge (html).css ({opacity: 0}). appendTo ($ container );
  88. $ NewElems. imagesLoaded (function (){
  89. $ NewElems. animate ({opacity: 1 });
  90. $ Container. masonry ('append', $ newElems, true );
  91. });
  92. // Once the request is completed, set on to false. you can perform the next request.
  93. Loading. data ("on", false );
  94. }
  95. Loading. fadeOut ();
  96. },
  97. "Json"
  98. );
  99. }
  100. });
  101. });
  102.  
  103.  
  104.  

Action code

  1. // Initialize the data
  2. Public function lists (){
  3. $ Data = D ('info')-> order ('Id desc')-> limit (10)-> select ();
  4. $ This-> assign ('data', $ data );
  5. $ This-> display ();
  6. }
  7. // Obtain the data of a request
  8. Public function getMore (){
  9. // Obtain The Last id
  10. If (! Emptyempty ($ _ GET ['lastid']) $ map ['id'] = array ('Lt ', $ _ GET ['lastid']);
  11. $ Data = D ('info')-> where ($ map)-> order ('Id desc')-> limit (10)-> select ();
  12. $ This-> ajaxReturn ($ data );
  13. }

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.

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.