[thelist] JS: Resizing an image?

Kowalkowski, Lee (ASPIRE) lee.kowalkowski at hmrcaspire.com
Thu Aug 25 11:55:31 CDT 2005

> -----Original Message-----
> From: Frank [mailto:lists at frankmarion.com]
> Sent: Thursday, August 25, 2005 5:16 PM
> How would you go about it?
>     <script type="text/javascript">
>        i = document.getElementById('artist_portrait')
>        ih = i.height;
>        h = document.getElementById('container').offsetHeight; //div
>        // i.setAttribute("height",h);  // don't work
>         ih = h; // this doesn't work either
>        i.height = h;
>        // alert(i +' '+ih+' '+h);
>    </script>

The syntax {image.height = newHeight;} should work a treat.  But...

If on your page, your container is stretching to be as big as your image,
then wont {container.offsetHeight} always be equal to {image.height} (less
any padding)?


If your container height is constant, then can't you just do {image.height =

Do you want to avoid altering the aspect ratio of these images when
adjusting the height?  In which case you'll also need {image.width *=
container.offsetHeight / image.height;}.

- LK.

Our e-mail domain has now changed from iraspire.com to hmrcaspire.com. Please update your address books.

More information about the thelist mailing list