Getting properties width, height dynamically generated image

Discussion of bugs in Seamonkey
Post Reply
mw22
Posts: 2379
Joined: November 19th, 2002, 5:37 pm

Getting properties width, height dynamically generated image

Post by mw22 »

Hi there,
Testcase:
http://home.hccnet.nl/m.wargers/test/mo ... mgtest.htm
Clicking on the link and an image will be created.
When you look at the statusbar, you can see the (offset)width and (offset)height properties of the (first) image just before and after appendchild.
I can imagine that these properties aren't available before appendchild (however I think it's possible in IE to use them), but after appendchild, these properties should be assigned by the browser I think.
Am I wrong here? Or is there already a bug report?

Thanks and regards, Martijn
User avatar
laszlo
Posts: 5225
Joined: November 4th, 2002, 6:13 pm
Location: .de
Contact:

Post by laszlo »

If I'm not mistaken, .offsetWidth and .offsetHeight are properties of Microsoft's all object. It's not very likely that they're going to work in Mozilla as expected.
mw22
Posts: 2379
Joined: November 19th, 2002, 5:37 pm

Post by mw22 »

If I use the getcomputedstyle version to detect the width and height of the image, I get the same values as offsetwidth and offsetheight.
The first time I get wrong values 24 and 24, but after I refresh and then click another time I get the correct values 75 and 56.
The problem for me is: There doesn't seem to be a way to get the width and height of the image without setting it by myself.
User avatar
WillyWonka
Posts: 212
Joined: November 5th, 2002, 12:25 pm
Location: Toronto
Contact:

Post by WillyWonka »

This is a bookmarklet that I use (It zooms all the images on a page). It might help.
<code>
javascript:(function(){
function zoomImage(image, amt) {
if(image.initialHeight == null) {
/* avoid losing height information due to
integer rounding while zooming out */
image.initialHeight = image.height;
image.initialWidth = image.width;
image.scalingFactor = 1;
}
image.scalingFactor *= amt;
image.width = image.scalingFactor * image.initialWidth;
image.height = image.scalingFactor * image.initialHeight;
}
for (i=0; i<document.images.length; ++i)
zoomImage(document.images[i], 2); })();
</code>
mw22
Posts: 2379
Joined: November 19th, 2002, 5:37 pm

Post by mw22 »

Thanks for your reply WillyWonka. I've used your case to make another (messy) testcase:
http://home.hccnet.nl/m.wargers/test/mo ... gtest2.htm
I see now what the problem is. The image attributes are not available at runtime. If I set a timeout('function()',0) then I don't have that problem.
I find this a bit weird. Shouldn't image width and height attibutes be available at runtime?
Post Reply