Watefaller.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // 吴春杰 傅昊
  2. Namespace.register("U.Control.wafaer"); //注册命名空间
  3. //window.onload = function () {
  4. // U.Control.wafaer.init();
  5. //}
  6. U.Control.wafaer.Minimum = 0; //获取最小高度
  7. U.Control.wafaer.list = 0; //获取列数
  8. U.Control.wafaer.fixedWidth = 0; //获取width
  9. U.Control.wafaer.arrimg = ["http://d.1473.cn/controls/phone/Watefall_phone/img/wafa0.png", "http://d.1473.cn/controls/phone/Watefall_phone/img/wafa1.png", "http://d.1473.cn/controls/phone/Watefall_phone/img/wafa2.png", "http://d.1473.cn/controls/phone/Watefall_phone/img/wafa3.png", "http://d.1473.cn/controls/phone/Watefall_phone/img/wafa4.png", "http://d.1473.cn/controls/phone/Watefall_phone/img/wafa5.png", "http://d.1473.cn/controls/phone/Watefall_phone/img/wafa6.png"]
  10. U.Control.wafaer.AA = function () {
  11. var C_B = $$("div", { "className": "CCB" });
  12. U.Control.wafaer.init(C_B);
  13. return C_B;
  14. }
  15. U.Control.wafaer.init = function (C_B) { // 调用函数U.Control.wafa.init() 返回div
  16. var ranH; //定义一个随机高度
  17. $("body")[0].style.cssText += "width:100%;overflow:auto;";
  18. if (document.body.offsetWidth <= 800) {
  19. if (U.Control.wafaer.list == 2 || U.Control.wafaer.fixedWidth == 48) {
  20. return;
  21. }
  22. U.Control.wafaer.list = 2; //需要的列数
  23. U.Control.wafaer.fixedWidth = 48; //固定宽度
  24. ranH = (function () { //图片高度
  25. return parseInt(Math.floor(Math.random() * 100) + 150);
  26. });
  27. }
  28. else {
  29. if (U.Control.wafaer.list == 4 || U.Control.wafaer.fixedWidth == 23.5) {
  30. return;
  31. }
  32. ranH = (function () { //图片高度
  33. return parseInt(Math.floor(Math.random() * 100) + 220);
  34. });
  35. U.Control.wafaer.list = 4;
  36. U.Control.wafaer.fixedWidth = 23.5;
  37. }
  38. if ($(".UUU")[0]) {
  39. $("body")[0].innerHTML = "";
  40. }
  41. var U_A = $$("div", { "className": "UUU", "style": { "cssText": "clear:both;width:77%;height:100%;"} }, C_B/*$("body")[0]*/);
  42. var mixH = {}; //装载列数div 的最小height
  43. var arrdiv = []; //装载所有div
  44. var row = 1; //获取排数
  45. var i, a, b;
  46. for (i = 0; i < U.Control.wafaer.list; i++) { //循环需要的多少列数
  47. var listdiv = $$("div", { "style": { "cssText": "float:left;min-height:10px;margin-right:1.5%;", "width": U.Control.wafaer.fixedWidth + "%" }, className: "listcolumns" }, U_A);
  48. }
  49. for (a = 0; a < 100; a++) { //要循环出多少个数据
  50. var ndiv = $$("div", { "style": { "cssText": "font-size:30px;text-align:center;background:#fff;margin-bottom:20px;position:relative;width:100%;" }, className: "DateC" });
  51. var img = $$("img", { "style": { "cssText": "margin:auto;width:95%;padding-top:5px;", "height": ranH() + "px" }, "src": U.Control.wafaer.arrimg[Math.floor(Math.random() * U.Control.wafaer.arrimg.length)] }, ndiv);
  52. var wz = $$("div", { "style": { "cssText": "diplay:inline-block;text-align:center;padding:15px 0;" }, innerHTML: a + 1 }, ndiv);
  53. arrdiv[a] = ndiv;
  54. }
  55. console.log(arrdiv);
  56. for (b = 0; b < U.Control.wafaer.list; b++) { //one row number
  57. U_A.children[b].appendChild(arrdiv[b]);
  58. mixH[b] = arrdiv[b].parentNode.offsetHeight;
  59. }
  60. U.Control.wafaer.ggy(mixH); // 获取当前列数的最小高度
  61. var $a; //判断当前最小高度的位置;
  62. var c, d, ii,LmixH;
  63. for (c = 0; c < arrdiv.length; c++) { //循环所有div的长度
  64. if (c % U.Control.wafaer.list == 0 && c != 0) { row++; } //求当前的模
  65. if (c < (row * U.Control.wafaer.list) && c >= (row - 1) * U.Control.wafaer.list) {
  66. if (arrdiv[c].parentNode.children[row]) { continue; }
  67. if (parseInt(arrdiv[c].parentNode.offsetHeight) == U.Control.wafaer.Minimum) {//判断当前行高是否为列高中最低的
  68. LmixH = arrdiv[c].parentNode; //获取当前行数高度最低的div
  69. for (d = 0; d < arrdiv.length; d++) {
  70. if (d > (U.Control.wafaer.list * row - 1) && d < U.Control.wafaer.list * (row + 1)) {
  71. if (U.Control.wafaer.list * row == d) {
  72. LmixH.appendChild(arrdiv[d]);
  73. if (d == arrdiv.length - 1) { return; } //最后一排只出现一个时,跳出全部循环
  74. for (ii = 0; ii < U.Control.wafaer.list; ii++) {
  75. if (LmixH.parentNode.children[ii] == LmixH) {
  76. $a = ii;
  77. mixH[$a] = LmixH.offsetHeight;
  78. }
  79. }
  80. }
  81. else {
  82. if (U_A.children[$a].children[row]) { $a++; }
  83. else { $a = 0; }
  84. if ($a == U.Control.wafaer.list) { $a = 0; }
  85. U_A.children[$a].appendChild(arrdiv[d]);
  86. mixH[$a] = U_A.children[$a].offsetHeight;
  87. if (d == arrdiv.length - 1 || d == arrdiv.length) { //阻挡最后一排错位 d到最后一个并跳出循环
  88. if (d % U.Control.wafaer.list == 1 || d % U.Control.wafaer.list == 2 || d % U.Control.wafaer.list == 3) { return; }
  89. }
  90. }
  91. }
  92. }
  93. U.Control.wafaer.ggy(mixH); // 获取当前列数的最小高度
  94. }
  95. }
  96. }
  97. }
  98. U.Control.wafaer.ggy = function (mixH) { //获取mix Height
  99. var arrMixH = []; //装载2个mixHeight
  100. var MixHHH = 0; //获取最小高度判断
  101. var i;
  102. for (i = 0; i < U.Control.wafaer.list; i++) {
  103. if (i == (U.Control.wafaer.list - 1)) {
  104. if (U.Control.wafaer.list == 1) {
  105. U.Control.wafa.Minimum = mixH[i]; //更新最小列高
  106. }
  107. continue;
  108. }
  109. arrMixH[i] = parseInt(mixH[i]); //给每个parseInt判断最小高度
  110. arrMixH[i + 1] = parseInt(mixH[i + 1]);
  111. MixHHH = Math.min(
  112. arrMixH[i], arrMixH[i + 1]
  113. );
  114. if (U.Control.wafaer.Minimum < MixHHH) {
  115. if (i == 0) {
  116. U.Control.wafaer.Minimum = MixHHH;
  117. }
  118. }
  119. else {
  120. U.Control.wafaer.Minimum = MixHHH;
  121. }
  122. }
  123. }
  124. //window.onresize = function () {
  125. // U.Control.wafaer.init(); //当窗口发生改变时,调取U.Control.wafaer.init()函数
  126. //}