waterfall.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // 吴春杰 傅昊
  2. Namespace.register("U.Control.wafa"); //注册命名空间
  3. //window.onload = function () {
  4. // U.Control.wafa.start();
  5. //}
  6. U.Control.wafa.start = function () { //页面加载第一个函数,生成文本框选项 调用函数U.Control.wafa.start() 返回参数
  7. var startA = $$("div", { "style": { "cssText": "display:inline-block;"} }); //创建名为startA的div包含列宽选项
  8. var startB = $$("input", { "style": { "cssText": "width:120px;height:26px;float:left;" }, placeholder: "列数" }, startA); //创建div,定义列数
  9. var startC = $$("input", { "style": { "cssText": "width:120px;height:26px;float:left;" }, placeholder: "宽度" }, startA); //创建div,定义宽度
  10. var Select = $$("select", { "style": { "cssText": "width:120px;height:30px;float:left;" }, className: "SeWidth" }, startA); //创建div,定义宽度的单位
  11. $$("option", { "style": { "cssText": "width:120px;height:30px;float:left;" }, innerHTML: "px" }, Select);
  12. $$("option", { "style": { "cssText": "width:120px;height:30px;float:left;" }, innerHTML: "%" }, Select);
  13. var startD = $$("button", { "style": { "cssText": "width:120px;height:30px;float:left;" }, innerHTML: "确定", className: "SundD" }, startA);//创建button绑定点击事件
  14. // startC.onclick = function () {
  15. // alert(1);
  16. // }
  17. startD.onclick = function () { //创建点击函数
  18. if (startB.value > 7 || startB.value < 1) { alert("列数不能大于7或者小于1"); return; }
  19. if ($(".SeWidth")[0].value == "px") { if (startC.value > (document.body.offsetWidth /(parseInt(startB.value)+1)) || startC.value < (document.body.offsetWidth / startC.value)) { alert("宽度不符,请重新设置"); return; } }
  20. if ($(".SeWidth")[0].value == "%") {
  21. if (startC.value > parseInt((Math.round(1 / startB.value * 10000) / 100.00 + "%"))-2 || //判断百分比宽度是否符合页面设置
  22. startC.value < parseInt((Math.round(1 / startB.value * 10000) / 100.00 + "%"))/3) { alert("宽度不符,请重新设置"); return; } }
  23. U.Control.wafa.ii(parseInt(startB.value), parseInt(startC.value)); //判断高度列数,并触发U.Control.wafa.ii();
  24. }
  25. return startA;
  26. }
  27. U.Control.wafa.ii = function (list, Width) { //先创建列DIV,判断并创建子DIV添加到列DIV中
  28. if ($("#oDivID")[0]) { $("#oDivID")[0].parentNode.removeChild($("#oDivID")[0]) }
  29. var Boxdiv = $$("div", { "style": { "cssText": "position:relative;margin-top:20px;"},id:"oDivID" }, $("body")[0]);
  30. U.Control.wafa.init(list, Width, Boxdiv); //
  31. }
  32. U.Control.wafa.Minimum=0; //获取最小高度
  33. U.Control.wafa.init = function (list, fixedWidth, Boxdiv) { // 调用函数U.Control.wafa.init() 返回div
  34. // var fixedWidth = 200; //固定宽度
  35. // var list = 4; //需要的列数
  36. var ranH = (function () { //随机高度
  37. return parseInt(Math.random() * 300 + 50);
  38. });
  39. var arrdiv = []; //装载所有div
  40. var mixH = {}; //装载列数div 的最小height
  41. var row = 1; //获取排数
  42. for (var i = 0; i < list; i++) { //循环需要的多少列数
  43. var listdiv = $$("div", { "style": { "cssText": "float:left;min-height:10px;margin:0 0 0 20px;", "width": fixedWidth + $(".SeWidth")[0].value }, className: "listcolumns" }, Boxdiv);
  44. }
  45. for (var a = 0; a < 10; a++) { //要循环出多少个数据
  46. var ndiv = $$("div", { "style": { "cssText": "font-size:30px;text-align:center;border:1px solid #f0f0f0;box-shadow:0 0 2px #666;margin-bottom:20px;position:relative;width:100%;", "height": ranH() + "px" }, innerHTML: a + 1, className: "DateC" });
  47. var adiv=$$("")
  48. arrdiv[a] = ndiv;
  49. }
  50. for (var b = 0; b < list; b++) { //one row number
  51. $(".listcolumns")[b].appendChild(arrdiv[b]);
  52. mixH[b] = arrdiv[b].parentNode.offsetHeight;
  53. }
  54. U.Control.wafa.ggy(list, mixH); // 获取当前列数的最小高度
  55. var $a; //判断当前最小高度的位置;
  56. for (var c = 0; c < arrdiv.length; c++) { //循环所有div的长度
  57. if (c % list == 0 && c != 0) { row++; } //求当前的模
  58. if (c < (row * list) && c >= (row - 1) * list) {
  59. if (arrdiv[c].parentNode.children[row]) { continue; }
  60. if (parseInt(arrdiv[c].parentNode.offsetHeight) == U.Control.wafa.Minimum) {//判断当前行高是否为列高中最低的
  61. var LmixH = arrdiv[c].parentNode; //获取当前行数高度最低的div
  62. for (var d = 0; d < arrdiv.length; d++) {
  63. if (d > (list * row - 1) && d < list * (row + 1)) {
  64. if (list * row == d) {
  65. LmixH.appendChild(arrdiv[d]);
  66. if (d == arrdiv.length - 1) { return; }
  67. for (var i = 0; i < LmixH.parentNode.children.length; i++) {
  68. if (LmixH.parentNode.children[i] == LmixH) {
  69. $a = i;
  70. mixH[$a] = LmixH.offsetHeight;
  71. }
  72. }
  73. }
  74. else {
  75. if ($(".listcolumns")[$a].children[row]) { $a++; }
  76. else { $a = 0; }
  77. if ($a == list) { $a = 0; }
  78. $(".listcolumns")[$a].appendChild(arrdiv[d]);
  79. mixH[$a] = $(".listcolumns")[$a].offsetHeight;
  80. }
  81. }
  82. }
  83. U.Control.wafa.ggy(list, mixH); // 获取当前列数的最小高度
  84. }
  85. }
  86. }
  87. }
  88. U.Control.wafa.ggy = function (list, mixH) { //获取mix Height
  89. var arrMixH = []; //装载2个mixHeight
  90. var MixHHH = 0; //获取最小高度判断
  91. for (var i = 0; i < list; i++) {
  92. if (i == (list - 1)) {
  93. if (list == 1) {
  94. U.Control.wafa.Minimum = mixH[i]; //更新最小列高
  95. }
  96. continue;
  97. }
  98. arrMixH[i] = parseInt(mixH[i]); //给每个parseInt判断最小高度
  99. arrMixH[i + 1] = parseInt(mixH[i + 1]);
  100. MixHHH = Math.min(
  101. arrMixH[i], arrMixH[i + 1]
  102. );
  103. if (U.Control.wafa.Minimum < MixHHH) {
  104. if (i == 0) {
  105. U.Control.wafa.Minimum = MixHHH;
  106. }
  107. }
  108. else {
  109. U.Control.wafa.Minimum = MixHHH;
  110. }
  111. }
  112. }