123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- // 吴春杰 傅昊
- Namespace.register("U.Control.wafaer"); //注册命名空间
- //window.onload = function () {
- // U.Control.wafaer.init();
- //}
- U.Control.wafaer.Minimum = 0; //获取最小高度
- U.Control.wafaer.list = 0; //获取列数
- U.Control.wafaer.fixedWidth = 0; //获取width
- 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"]
- U.Control.wafaer.AA = function () {
- var C_B = $$("div", { "className": "CCB" });
- U.Control.wafaer.init(C_B);
- return C_B;
- }
- U.Control.wafaer.init = function (C_B) { // 调用函数U.Control.wafa.init() 返回div
- var ranH; //定义一个随机高度
- $("body")[0].style.cssText += "width:100%;overflow:auto;";
- if (document.body.offsetWidth <= 800) {
- if (U.Control.wafaer.list == 2 || U.Control.wafaer.fixedWidth == 48) {
- return;
- }
- U.Control.wafaer.list = 2; //需要的列数
- U.Control.wafaer.fixedWidth = 48; //固定宽度
- ranH = (function () { //图片高度
- return parseInt(Math.floor(Math.random() * 100) + 150);
- });
- }
- else {
- if (U.Control.wafaer.list == 4 || U.Control.wafaer.fixedWidth == 23.5) {
- return;
- }
- ranH = (function () { //图片高度
- return parseInt(Math.floor(Math.random() * 100) + 220);
- });
- U.Control.wafaer.list = 4;
- U.Control.wafaer.fixedWidth = 23.5;
- }
- if ($(".UUU")[0]) {
- $("body")[0].innerHTML = "";
- }
- var U_A = $$("div", { "className": "UUU", "style": { "cssText": "clear:both;width:77%;height:100%;"} }, C_B/*$("body")[0]*/);
- var mixH = {}; //装载列数div 的最小height
- var arrdiv = []; //装载所有div
- var row = 1; //获取排数
- var i, a, b;
- for (i = 0; i < U.Control.wafaer.list; i++) { //循环需要的多少列数
- var listdiv = $$("div", { "style": { "cssText": "float:left;min-height:10px;margin-right:1.5%;", "width": U.Control.wafaer.fixedWidth + "%" }, className: "listcolumns" }, U_A);
- }
- for (a = 0; a < 100; a++) { //要循环出多少个数据
- var ndiv = $$("div", { "style": { "cssText": "font-size:30px;text-align:center;background:#fff;margin-bottom:20px;position:relative;width:100%;" }, className: "DateC" });
- 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);
- var wz = $$("div", { "style": { "cssText": "diplay:inline-block;text-align:center;padding:15px 0;" }, innerHTML: a + 1 }, ndiv);
- arrdiv[a] = ndiv;
- }
- console.log(arrdiv);
- for (b = 0; b < U.Control.wafaer.list; b++) { //one row number
- U_A.children[b].appendChild(arrdiv[b]);
- mixH[b] = arrdiv[b].parentNode.offsetHeight;
- }
- U.Control.wafaer.ggy(mixH); // 获取当前列数的最小高度
- var $a; //判断当前最小高度的位置;
- var c, d, ii,LmixH;
- for (c = 0; c < arrdiv.length; c++) { //循环所有div的长度
- if (c % U.Control.wafaer.list == 0 && c != 0) { row++; } //求当前的模
- if (c < (row * U.Control.wafaer.list) && c >= (row - 1) * U.Control.wafaer.list) {
- if (arrdiv[c].parentNode.children[row]) { continue; }
- if (parseInt(arrdiv[c].parentNode.offsetHeight) == U.Control.wafaer.Minimum) {//判断当前行高是否为列高中最低的
- LmixH = arrdiv[c].parentNode; //获取当前行数高度最低的div
- for (d = 0; d < arrdiv.length; d++) {
- if (d > (U.Control.wafaer.list * row - 1) && d < U.Control.wafaer.list * (row + 1)) {
- if (U.Control.wafaer.list * row == d) {
- LmixH.appendChild(arrdiv[d]);
- if (d == arrdiv.length - 1) { return; } //最后一排只出现一个时,跳出全部循环
- for (ii = 0; ii < U.Control.wafaer.list; ii++) {
- if (LmixH.parentNode.children[ii] == LmixH) {
- $a = ii;
- mixH[$a] = LmixH.offsetHeight;
- }
- }
- }
- else {
- if (U_A.children[$a].children[row]) { $a++; }
- else { $a = 0; }
- if ($a == U.Control.wafaer.list) { $a = 0; }
- U_A.children[$a].appendChild(arrdiv[d]);
- mixH[$a] = U_A.children[$a].offsetHeight;
- if (d == arrdiv.length - 1 || d == arrdiv.length) { //阻挡最后一排错位 d到最后一个并跳出循环
- if (d % U.Control.wafaer.list == 1 || d % U.Control.wafaer.list == 2 || d % U.Control.wafaer.list == 3) { return; }
- }
- }
- }
- }
- U.Control.wafaer.ggy(mixH); // 获取当前列数的最小高度
- }
- }
- }
- }
- U.Control.wafaer.ggy = function (mixH) { //获取mix Height
- var arrMixH = []; //装载2个mixHeight
- var MixHHH = 0; //获取最小高度判断
- var i;
- for (i = 0; i < U.Control.wafaer.list; i++) {
- if (i == (U.Control.wafaer.list - 1)) {
- if (U.Control.wafaer.list == 1) {
- U.Control.wafa.Minimum = mixH[i]; //更新最小列高
- }
- continue;
- }
- arrMixH[i] = parseInt(mixH[i]); //给每个parseInt判断最小高度
- arrMixH[i + 1] = parseInt(mixH[i + 1]);
- MixHHH = Math.min(
- arrMixH[i], arrMixH[i + 1]
- );
- if (U.Control.wafaer.Minimum < MixHHH) {
- if (i == 0) {
- U.Control.wafaer.Minimum = MixHHH;
- }
- }
- else {
- U.Control.wafaer.Minimum = MixHHH;
- }
- }
- }
- //window.onresize = function () {
- // U.Control.wafaer.init(); //当窗口发生改变时,调取U.Control.wafaer.init()函数
- //}
|