Skip to content

Instantly share code, notes, and snippets.

@ysbaddaden
Created September 22, 2014 20:12
Show Gist options
  • Save ysbaddaden/065c9a74cf1f7bc40385 to your computer and use it in GitHub Desktop.
Save ysbaddaden/065c9a74cf1f7bc40385 to your computer and use it in GitHub Desktop.
js-screen-height-directive.js
// Fixes the height of an element to be at least the height of the current
// screen, minus it's current offset (so it fills the screen vertically).
powell.directive('jsScreenHeight', function () {
var $window = angular.element(window);
return {
restrict: 'C',
link: function (scope, element) {
var resize = function () {
// TODO: don't require jquery just for computing the offset
var top = Math.round(element.offset().top);
element.css('height', window.innerHeight - top + 'px');
};
resize();
$window.on('resize', resize);
$window.on('orientationchange', resize);
element.on('$destroy', function () {
$window.off('resize', resize);
$window.off('orientationchange', resize);
});
scope.$on("jsScreenHeight:update", resize);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment