I have a div which contains a image.Now based on the naturalWidth/naturalHeight and offsetwidth/offsetHeight of the image i am running a function and doing some calculation to show a absolute layer on top of the div.Right now i am using the below code
angular.element(document).ready(function () {
var actual_width = document.getElementById("image_id").naturalWidth;
var actual_height = document.getElementById("image_id").naturalHeight;
var width = document.getElementById("image_id").offsetWidth;
var height = document.getElementById("image_id").offsetHeight;}) //my calculation })
Image data is coming from api. Now the problem issometimes naturalWidth shows undefined even if i put it inside document ready function.
1.How do i run the function after content loaded or it is changed(i call the api again without refreshing to get new data)
2.how do i run the same function for every width and height changes of the div(when i do responsive).
I am working on a angularjs(angular 1.x) application
code to call the api
$http({
method: 'GET',
url: 'some url' + $scope.cursor
}).then(function successCallback(response) {//i get
$scope.formItems = [response.data[0]];
}
in html
<div class="image-wrapper" ng-repeat="item in formItems">
<div style="{{style1}}" class="img-src relative">
<img ng-src="{{item['img_url']}}" alt="Source" class="main-image" id="image_id">
<!-- below section should get some style based on the image width and height,so i need some something like a funciton which calls everytime page is loaded or if the image changes or window resize -->
<div class="top-section" id="image-top-box-id"></div>
<div class="bottom-section" id="image-bottom-box-id"></div>
</div>
</div>