Created
September 22, 2014 20:12
-
-
Save ysbaddaden/065c9a74cf1f7bc40385 to your computer and use it in GitHub Desktop.
js-screen-height-directive.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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