计算同行等高方法
2019-08-21 本文已影响0人
leleo
window.Base = window.Base || function () {};
// 计算同行等高方法
// 如果层级只有两级,传2个参数,如果层级有三级,传3个参数,
Base.prototype.setHeight = function (obj, obj2, obj3) {
if (!this.resizeStackLock) {
this.resizeStack.push({
fn: this.v3SetHeight,
params: arguments
});
}
var This = $(obj);
var args = arguments;
This.each(function () {
var _this = $(this),
oList = _this.find(obj2),
oList_len = oList.length,
oBox_w = _this.width() + 10,
oList_w = oList.width(),
oColumn_len = Math.floor(oBox_w / oList_w),
oRow_len = Math.ceil(oList_len / oColumn_len),
oList_H = 0,
oList_obj = null;
if (args.length == 2) {
oList.height('auto');
} else {
oList.find(obj3).height('auto');
}
for (var i = 0; i < oRow_len; i++) {
for (var j = i * oColumn_len; j < oColumn_len * (i + 1); j++) {
oList.eq(j).addClass('oList_obj');
if (args.length == 2) {
var H = oList.eq(j).height();
} else {
var H = oList.eq(j).find(obj3).height();
}
H > oList_H ? oList_H = H : oList_H;
oList_obj = $('.oList_obj');
}
if (args.length == 2) {
oList_obj.height(oList_H);
} else {
oList_obj.find(obj3).height(oList_H);
}
oList_obj.removeClass('oList_obj');
oList_H = 0;
}
});
}
var baseLib = new Base();
baseLib.setHeight() ////5种尺寸图片的图片替换