Skip to content

Instantly share code, notes, and snippets.

@lucasff
Created September 13, 2016 17:36
Show Gist options
  • Save lucasff/335c04619045f415d82d332f8c3385b8 to your computer and use it in GitHub Desktop.
Save lucasff/335c04619045f415d82d332f8c3385b8 to your computer and use it in GitHub Desktop.
'use strict';
/**
* @ngdoc directive
* @name ttmApp.directive:CopyHeight
* @description
* Set the height of an element base on another element
*/
angular.module('ttmApp')
.directive('copyHeight', function ($interval, $timeout) {
var $ = window.jQuery;
var elements = new Set();
var values = [];
return {
restrict: 'A',
scope: {
'watchedElement': '='
},
link: function (scope, element, attributes) {
function setHeight() {
var targetHeight = Array.max(values);
console.log(targetHeight);
Array.from(elements).forEach(function(item) {
item.height(targetHeight);
});
}
function processElements() {
elements.add(element);
values.push($('#' + attributes.copyHeight).height());
$timeout(setHeight, 1000);
}
//$(window).resize(setHeight);
//$(window).load(setHeight);
$interval(processElements, 500);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment