Skip to content

Instantly share code, notes, and snippets.

@mjamin
Last active November 2, 2020 15:41
Show Gist options
  • Save mjamin/db01bd1762066ac1156b to your computer and use it in GitHub Desktop.
Save mjamin/db01bd1762066ac1156b to your computer and use it in GitHub Desktop.
AngularJS fill-height directive: sets an element's height so it fills up the remaining space in the viewport
angular.module('app').directive('fillHeight', [
'$window',
function ($window) {
return {
restrict: 'A',
link: function (scope, e) {
var initialHeight = e[0].offsetHeight;
var fill = function () {
angular.element(e).css('height', Math.max(initialHeight, $window.innerHeight - e[0].offsetTop) + 'px');
};
scope.$watch(function () {
return e[0].offsetTop;
}, function () {
fill();
});
angular.element($window).bind('resize', function () {
fill();
});
}
};
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment