D
dax
This is a script to scale thumbnails depending on the size specified
by an application setting. I've dummied down the script to make it a
little more understandable.
I think I'm getting closer to solving this, but it appears that in IE
the onload event fires too early when used on an image.
Here is my script.
function scaleImage(imageId, size)
{
var pic=document.getElementById(imageId);
var w=pic.width;
var h=pic.height;
if (h > w)
{
if (h > size)
{
var f = h / size;
var newwidth=w / f;
var newheight=h / f;
}
else
{
var newwidth=w;
var newheight=h;
}
}
else if (w >= h)
{
if (w > size)
{
var f = w / Size;
var newwidth=w / f;
var newheight=h / f;
}
else
{
var newwidth=w;
var newheight=h;
}
}
pic.display = 'visible';
pic.height = newheight;
pic.width = newwidth;
}
Images are loaded such as below.
<img src="image1.gif" id="image1"
onload="ScaleImage('image1','150')">
<img src="image2.gif" id="image2"
onload="ScaleImage('image2','150')">
<img src="image3.gif" id="image3"
onload="ScaleImage('image3','150')">
<img src="image4.gif" id="image4"
onload="ScaleImage('image4','150')">
etc.....
What happens is inconsitantly when the images are loaded, the onload
event triggers too early and the height and width attributes are
registered as 0.
Is there a way to force the onload event to take place after the image
has loaded?
Thanks
dax
by an application setting. I've dummied down the script to make it a
little more understandable.
I think I'm getting closer to solving this, but it appears that in IE
the onload event fires too early when used on an image.
Here is my script.
function scaleImage(imageId, size)
{
var pic=document.getElementById(imageId);
var w=pic.width;
var h=pic.height;
if (h > w)
{
if (h > size)
{
var f = h / size;
var newwidth=w / f;
var newheight=h / f;
}
else
{
var newwidth=w;
var newheight=h;
}
}
else if (w >= h)
{
if (w > size)
{
var f = w / Size;
var newwidth=w / f;
var newheight=h / f;
}
else
{
var newwidth=w;
var newheight=h;
}
}
pic.display = 'visible';
pic.height = newheight;
pic.width = newwidth;
}
Images are loaded such as below.
<img src="image1.gif" id="image1"
onload="ScaleImage('image1','150')">
<img src="image2.gif" id="image2"
onload="ScaleImage('image2','150')">
<img src="image3.gif" id="image3"
onload="ScaleImage('image3','150')">
<img src="image4.gif" id="image4"
onload="ScaleImage('image4','150')">
etc.....
What happens is inconsitantly when the images are loaded, the onload
event triggers too early and the height and width attributes are
registered as 0.
Is there a way to force the onload event to take place after the image
has loaded?
Thanks
dax