Skip to content

Instantly share code, notes, and snippets.

@KillerCodeMonkey
Created January 7, 2016 08:06
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 KillerCodeMonkey/832af4de84c08fccf909 to your computer and use it in GitHub Desktop.
Save KillerCodeMonkey/832af4de84c08fccf909 to your computer and use it in GitHub Desktop.
Angular directive to get size of an element
angular.module('app', ['ionic']).directive('elementSize', [
'$timeout',
function ($timeout) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
element.ready(function () {
var height,
width;
$timeout(function () {
height = element[0].offsetHeight;
width = element[0].offsetWidth;
if (attrs.key) {
scope[attrs.key] = {
height: height,
width: width
};
return;
}
scope.elementSize = {
height: height,
width: width
};
});
});
}
};
}
]);
// usage e.g. <ion-content element-size key="contentSize">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment