Jquery implements simple waterfall stream code and jquery waterfall code

Source: Internet
Author: User

Jquery implements simple waterfall stream code and jquery waterfall code

Test environment: ie8 ff13.0.1 chrome22

You can add the retrieved content by page to four divs in sequence. The pagination of the waterfall stream can be a second pagination in the unit of multiple pages (such as five pages), which can reduce the complexity of the background algorithm.

 

[Html]View plaincopy
  1. <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN"
  2. Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
  3. <Html>
  4. <Head>
  5. <Meta http-equiv = "content-type" content = "text/html; charset = UTF-8"/>
  6. <Title> waterfall flow </title>
  7. <Script type = "text/javascript" src = "../jquery-1.8.0.min.js"/> </script>
  8. <Style type = "text/css">
  9. Body {margin: 0px ;}
  10. # Main {width: 840px; margin: 0 auto ;}
  11. . Flow {float: left; width: 200px; margin: 5px; background: # ABC ;}
  12. </Style>
  13. <Script type = "text/javascript">
  14. $ (Document). ready (function (){
  15. // Initialize the content
  16. For (var I = 0; I <3; I ++ ){
  17. $ (". Flow"). each (function (){
  18. $ (This ). append ("<div style = \" width: 90%; height: "+ getRandom (200,300) +" px; margin: 5px auto; background: #159; \ "> </div> ");
  19. });
  20. }
  21. $ (Window). scroll (function (){
  22. // The height of the volume
  23. Var scrollTop = document. body. scrollTop | document.doc umentElement. scrollTop;
  24. // Page height
  25. Var pageHeight = $ (document). height ();
  26. // Visible area height
  27. Var viewHeight = $ (window). height ();
  28. // Alert (viewHeight );
  29. // When scrolling to the bottom
  30. If (scrollTop + viewHeight)> (pageHeight-20 )){
  31. If (scrollTop <1000) {// prevents unlimited growth
  32. For (var I = 0; I <2; I ++ ){
  33. $ (". Flow"). each (function (){
  34. $ (This ). append ("<div style = \" width: 90%; height: "+ getRandom (200,300) +" px; margin: 5px auto; background: #159; \ "> </div> ");
  35. });
  36. }
  37. }
  38. }
  39. });
  40. });
  41. /*
  42. * Obtain random numbers within a specified range
  43. * @ Param min, minimum value
  44. * @ Param max, maximum value
  45. */
  46. Function getRandom (min, max ){
  47. // Upper limit of x and lower limit of y
  48. Var x = max;
  49. Var y = min;
  50. If (x <y ){
  51. X = min;
  52. Y = max;
  53. }
  54. Var rand = parseInt (Math. random () * (x-y + 1) + y );
  55. Return rand;
  56. }
  57. </Script>
  58. </Head>
  59. <Body>
  60. <Div id = "main">
  61. <Div class = "flow"> </div>
  62. <Div class = "flow"> </div>
  63. <Div class = "flow"> </div>
  64. <Div class = "flow"> </div>
  65. </Div>
  66. </Body>
  67. </Html>


 


How to Write waterfall stream js Code

We recommend that you directly use the panel of ext.
 
Div css waterfall stream Layout

I have read that it is still a bit difficult to implement it with pure css. In fact, I cannot write it myself, because it is alignment on its top, feeling like no waterfall Flow

It is recommended that lz be implemented using js plug-ins

Search for the jquery. masonry jquery plug-in on the Internet and write it specifically for the waterfall stream. You can just reference the library and css code, which is the effect you want.

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.