D
dax
Hello,
I'm new at Javascript so please bear with me.
I have a page loading multiple images and then a script to resize the
images to all the same scale. I believe that the function to resize
the images is causing conflicts because I'm only using a simple global
variable, and I need to create an object for each image instead. But
I'm not sure how to do this.
The problem is only one or two of the images are loading, while the
others aren't displayed at all.
Heres the script
<script language="javascript">
function ScaleImage(ImageId, Size) {
IMG=document.getElementById(ImageId);
w=IMG.width;
h=IMG.height;
if (h > w)
{
if (h > Size)
{
f = h / Size;
IMG.width=w / f;
IMG.height=h / f;
}
else
{
IMG.width=w;
IMG.height=h;
}
}
else if (w >= h)
{
if (w > Size)
{
f = w / Size;
IMG.width=w / f;
IMG.height=h / f;
}
else
{
IMG.width=w;
IMG.height=h;
}
}
}
</script>
Then the images are loaded from a db query.
<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.....
I can't create an array because the numbering isn't always going to be
consecutive like I have in my example.
Any help would really be appreciated.
Thanks
I'm new at Javascript so please bear with me.
I have a page loading multiple images and then a script to resize the
images to all the same scale. I believe that the function to resize
the images is causing conflicts because I'm only using a simple global
variable, and I need to create an object for each image instead. But
I'm not sure how to do this.
The problem is only one or two of the images are loading, while the
others aren't displayed at all.
Heres the script
<script language="javascript">
function ScaleImage(ImageId, Size) {
IMG=document.getElementById(ImageId);
w=IMG.width;
h=IMG.height;
if (h > w)
{
if (h > Size)
{
f = h / Size;
IMG.width=w / f;
IMG.height=h / f;
}
else
{
IMG.width=w;
IMG.height=h;
}
}
else if (w >= h)
{
if (w > Size)
{
f = w / Size;
IMG.width=w / f;
IMG.height=h / f;
}
else
{
IMG.width=w;
IMG.height=h;
}
}
}
</script>
Then the images are loaded from a db query.
<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.....
I can't create an array because the numbering isn't always going to be
consecutive like I have in my example.
Any help would really be appreciated.
Thanks