Skip to content

Instantly share code, notes, and snippets.

@maztch
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maztch/d333bdd3493a2fc40978 to your computer and use it in GitHub Desktop.
Save maztch/d333bdd3493a2fc40978 to your computer and use it in GitHub Desktop.
angular full window width directive
'use strict';
//http://jsfiddle.net/maztch/efccbja5/7/
angular.module('app')
.directive('full', function($window) {
return({
restrict: 'A',
link: function ( $scope, element, attributes ) {
var w = angular.element($window);
var e = element;
$scope.getWindowDimensions = function () {
return {
'h': w.height(),
'w': w.width()
};
};
$scope.$watch($scope.getWindowDimensions, function (newValue, oldValue) {
var width = element.width();
var wwidth = newValue.w;
element.css('margin-left', '-'+((wwidth-width)/2)+'px');
element.css('margin-right', '-'+((wwidth-width)/2)+'px');
element.css('padding-left', ((wwidth-width)/2)+'px');
element.css('padding-right', ((wwidth-width)/2)+'px');
}, true);
}
});
})
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment