1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| layui.define(['jquery', 'element', 'util', 'laytpl'], function (exports) {
var $ = layui.jquery , element = layui.element , layer = layui.layer , util = layui.util , laytpl = layui.laytpl;
var gather = { waterfall: function () { var box = $(".layui-col-md3"); var boxWidth = box.eq(0).width(); var num = Math.floor($("#zone-list").width() / boxWidth); var boxArr = []; box.each(function (index, value) { var boxHeight = box.eq(index).height(); if (index < num) { boxArr[index] = boxHeight; } else { var minboxHeight = Math.min.apply(null, boxArr), minboxIndex = $.inArray(minboxHeight, boxArr); $(value).css({ "position": "absolute", "top": minboxHeight + 15, "left": box.eq(minboxIndex).position().left });
boxArr[minboxIndex] += box.eq(index).height() + 15; if (boxHeight + minboxHeight > $("#zone-list").height()) { $("#zone-list").height(150 + boxArr[minboxIndex]); } } });
}, json: function (url, data, func, options) { var that = this, type = typeof data === 'function'; if (type) { options = func func = data; data = {}; } options = options || {}; return $.ajax({ type: options.type || 'post', dataType: options.dataType || 'json', data: data, url: url, success: function (res) { func && func(res); }, error: function (e) { layer.msg('请求异常,请重试', {shift: 6}); options.error && options.error(e); } }); },
}; exports('common', gather); });
|
评论