This repository was archived by the owner on May 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathangular-matchheight.js
More file actions
52 lines (44 loc) · 1.7 KB
/
angular-matchheight.js
File metadata and controls
52 lines (44 loc) · 1.7 KB
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
/*
* Angular Match Height
* An angular directive to match heights of divs
*
*/
angular.module('angular-matchheight', [])
.directive('ilnMatchHeight', [
function () {
return {
restrict: 'A',
scope: {},
link: function ( scope, elm, attrs ) {
var i;
var heightsArray = [];
var largest = 0;
/**
* Return the largest number in the array
* @name largetsNo
* @param {Array} array - The array of heights
* @return {Number} the largest number
*/
var largetsNo = function( array ){
return Math.max.apply( Math, array );
};
// when the element has finished loading
elm.ready(function(){
// loop through all the children and get their heights
for ( i = 0; i < elm[0].childNodes.length; i++) {
// add the heights to the array if not undefined
// e.g a comment will be picked up
if( elm[0].childNodes[i].offsetHeight ){
heightsArray.push( elm[0].childNodes[i].offsetHeight );
}
}
// get the largest height
largest = largetsNo( heightsArray );
// add the height to the children
for ( i = 0; i < elm[0].childNodes.length; i++) {
elm.children().eq( i ).css( 'height', largest + 'px' );
}
});
}
};
}]);