1

I am using a FileReader to populate my images.

// i.e. .... e.target.result

If i set an image element source like this:

pic_upload_area.src = some_image;

I can get its dimensions like this:

width = pic_upload_area.clientWidth;

And things work fine. However if I now reset it to a new image like this:

pic_upload_area.src = '';
pic_upload_area.src = new_image;

and once again get the image like this:

width = pic_upload_area.clientWidth;

I find that it still has the old image width, and the new image has been malformed to fit the old image's dimensions.

I find it strange that it works only on the first attempt. How can I get clientWidth to update when I update the .src attribute of the image?

4

1 回答 1

1

最简单的方法是删除并重新创建pic_upload_area. 设置尺寸后,新图像src将符合旧尺寸。

于 2013-02-11T20:32:02.927 回答