Автовыравнивание блоков по высоте. Применяется часто в каталоге в списке карточке, когда по дизайну все карточки на линии одной высоты должны быть
$(document).load(function() {
if ($(window).width() >= 992) {
autoHeight('.eventsElementList .element', 3);
} else if ($(window).width() >= 768) {
autoHeight('.eventsElementList .element', 2);
}
});
$(window).resize(function() {
clearTimeout(window.resizedFinished);
window.resizedFinished = setTimeout(function(){
if ($(window).width() >= 992) {
autoHeight('.eventsElementList .element', 3);
} else if ($(window).width() >= 768) {
autoHeight('.eventsElementList .element', 2);
}
}, 250);
});
function autoHeight(selector, lineCount) { // lineCount - сколько элментов в линии
var objectList = {},
tempHeight = 0;
$.each($(selector), function( index, value) {
$(this).css('height', 'auto');
objectList[index] = $(this);
if (tempHeight < $(this).outerHeight()) {
tempHeight = $(this).outerHeight();
}
if (((index+1) % lineCount) == 0) {
for (var key in objectList) {
objectList[key].outerHeight(tempHeight);
delete objectList[key];
}
tempHeight = 0;
}
});
}