jquery implements a simple waterfall stream code

Source: Internet
Author: User

Test environment: IE8 ff13.0.1 Chrome22

You can fill the contents of the page into four Div, the waterfall flow of the page can be multiple pages (such as 5 pages) in two pages, so as to 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 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 being rolled away
  23. var scrolltop = document.body.scrolltop| |  Document.documentElement.scrollTop;
  24. Page height
  25. var pageheight = $ (document). Height ();
  26. Viewable 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) {//Prevent 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. * Gets the specified range of random numbers
  43. * @param min, minimum value
  44. * @param max, max value
  45. */
  46. function Getrandom (Min,max) {
  47. x upper limit, y lower limit
  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>


jquery implements a simple waterfall stream code

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.