Javascript calculate image size, after image load?

Try this: function loader(){ var imgH = this. Height; var imgW = this. Width; console.

Log(imgH, imgW); } var img = new Image(); img. Onload = loader; img. Src ='../images/pic1.jpeg.

This makes no sense: img. OnLoad = loader(img); you want to pass the actual function to the event: img. Onload = loader; and use this instead of img within the function.

Also you need to assign the event before changing the image's src property. Also note that there are numerous problems with the load event on images. From the jQuery manual on load(): Caveats of the load event when used with images A common challenge developers attempt to solve using the .load() shortcut is to execute a function when an image (or collection of images) have completely loaded.

There are several known caveats with this that should be noted. These are: It doesn't work consistently nor reliably cross-browser It doesn't fire correctly in WebKit if the image src is set to the same src as before It doesn't correctly bubble up the DOM tree.

I used this way: img. Onload = function(){//here wrote everything from loader}; And it was the only working solution I have found.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions