Last active
August 29, 2015 14:25
-
-
Save maztch/d333bdd3493a2fc40978 to your computer and use it in GitHub Desktop.
angular full window width directive
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
'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