Hi I'm trying to find an image element's height and width in order to resize it. However everytime I use elem.height() or elem.width() I get 0?
html
<div>
<img data-ng-src="{{photosrc}}" lightbox-resize-image>
</div>
directive.js
.directive('lightboxResizeImage', function() {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
console.log(elem.parent().width()); //==equals 575
console.log(elem.width()); //this always equals 0
}
});
See code below:
.directive('lightboxResizeImage', function() {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
console.log(elem.parent().width()); // =575
console.log(elem[0].offsetHeight);
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With