• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1247
  • Last Modified:

dynamically resize images on page load

I have an html file that can contain anywhere from 1 to (?)number of images on the html file. I'd like to have Javascript read the page before it loads and automatically resize the images
to a 1/4 of the width per image. Below is what I currently have:

code:
---------------
<html>
<head>
<script>
function resize(im) {
 im.width*=0.25;
}
</script>
</head>

<body>
<IMG alt="View actual size" hspace="2" src="documents/2005March01.jpg" vspace="2" border="0"
       onload="resize(this);">
<IMG alt="View actual size" hspace="2" src="documents/2005March02.jpg" vspace="2" border="0"
       onload="resize(this);">
<IMG alt="View actual size" hspace="2" src="documents/2005March03.jpg" vspace="2" border="0"
       onload="resize(this);">
</body>
</html>
----------------

The above works fine for the 1st time coming to the page, but when I come back to the page, the image(s) may or maynot appear. How do I keep the image(s) from disappearing? I need to be able to see all the images every time the page loads.
0
matthersjr
Asked:
matthersjr
  • 4
1 Solution
 
archrajanCommented:
change this
function resize(im) {
 im.width*=0.25;
}


to

function resize()
{
for(i=0; i <document.images.length;i++)
{
document.images[i].width *= 0,25;
}
}

and call it in the onload event of ur body tag
0
 
archrajanCommented:
oops typo:
 0,25;
shud be

 0.25;
0
 
matthersjrAuthor Commented:
works great, but I've got one image on the page that can not be reduced. How do I keep a header image from being resized?
0
 
archrajanCommented:
ok if the image name is say for example "matt"

function resize()
{
for(i=0; i <document.images.length;i++)
{
if(document.images[i].name != "matt")
document.images[i].width *= 0,25;
}
}
0
 
archrajanCommented:
Thanks so much for the points and the grade
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now