Last active
July 15, 2019 06:32
-
-
Save xto3na/1600495537d7de5b86a5 to your computer and use it in GitHub Desktop.
Выравнивание всех блоков по размеру
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
function equalizeHeights(selector) { | |
var heights = new Array(); | |
// Loop to get all element heights | |
$(selector).each(function() { | |
// Need to let sizes be whatever they want so no overflow on resize | |
$(this).css('height', 'auto'); | |
// Then add size (no units) to array | |
heights.push($(this).height()); | |
}); | |
// Find max height of all elements | |
var max = Math.max.apply( Math, heights ); | |
// Set all heights to max height | |
$(selector).each(function() { | |
$(this).css('height', max + 'px'); | |
}); | |
$('.all-tabs-wrapper').css('height', max + 'px'); | |
} | |
$(window).load(function() { | |
// Fix heights on page load | |
equalizeHeights('.tab-content'); | |
// Fix heights on window resize | |
$(window).resize(function() { | |
// Needs to be a timeout function so it doesn't fire every ms of resize | |
setTimeout(function() { | |
equalizeHeights('.tab-content'); | |
}, 120); | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment