开发者

Wrong image dimensions when it's dynamically loaded on a page the 1st time

I have the following piece of Javascript code on my web-page

var central_image = document.createElement("img")
central_image.setAttribute("src", imgs[curr_image_no - 1]);
central_image.setAttribute("name", "jpeg");
document.getElementById("photo").appendChild(central_image);
central_image.onload =  getDimensions(); //function that alerts image dimensions

Now, when the 开发者_JAVA技巧central_image is loaded for the 1st time in Firefox, its height always equals to 0. In IE its dimensions are 28 x 30 pixels. When I reload image, its dimensions are OK in both browsers.

I guess the problem is that function getDimensions() starts before image was loaded completely. How to change that?


central_image.onload =  getDimensions;

The other way runs getDimensions, and assigns its returned value to the onload event

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜