-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequalElementHeights.js
39 lines (34 loc) · 1.23 KB
/
equalElementHeights.js
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
$(document).ready(function(){
set_heights_equal();
$(".equalHeightElement").load(function() {
set_heights_equal();
});
});
$(".equalHeightElement").ready(function() {
set_heights_equal();
});
$( window ).resize(function() {
set_heights_equal();
});
function set_heights_equal () {
$(".equalHeightElement").css({"height":"300px"}); // set all to same height
//console.log('test');
var top_positions = [];
$(".equalHeightElement").each(function(){
var this_top_position = $(this).position().top;
if($.inArray(this_top_position, top_positions , 0 ) === -1) {
top_positions.push(this_top_position); // collect numbers for each top position
}
$(this).attr('row_number',this_top_position); // set row number to element
});
$(".equalHeightElement").css({"height":"auto"}); // set height to auto
$.each( top_positions, function( index, value ){ // loop rows
var largest_height = 0;
$('.equalHeightElement[row_number="'+value+'"]').each(function() { // find heighest element
if ($( this ).height() > largest_height) {
largest_height = $( this ).height();
}
});
$('.equalHeightElement[row_number="'+value+'"]').height(largest_height); // set heighest height to all of row
});
}