Click to See Complete Forum and Search --> : auto pic resize


neil9999
10-17-2003, 10:39 AM
Hi,

I have the following code which should make a picture as big as possible, whilst keeping its ratios:


<script language='javascript'>
function resize(){
var fh=document.body.clientHeight;
var fw=document.body.clientWidth;
var ph=document.getElementById('piccy').height;
var pw=document.getElementById('piccy').width;
var fr=fh/fw;
var pr=ph/pw;
if(fr>pr){document.getElementById('piccy').width="100%"};
else{document.getElementById('piccy').height="100%"};
}
</script>
</head>

<body onload="resize()">

<p><img border="0" src="cat.bmp" id="piccy" width="244" height="200"></p>


If I open this up, the image doesn't display at all. If I change the two 100%'s to just 100 then the picture shows up, but distorted, so the image src is right. Why isn't this working?

Thanks,

Neil

Phil Karras
10-17-2003, 11:42 AM
Well, the image is distorted because those values need to be:

...width="244" height="200"...

right? Use those values and the image will at least be the correct ratio.

Now, as to increasing its size...

I believe that question has been asked numerous times before, on this site, so you should first do a search.

If that doesn't work then try other boards as well and search them, I know at least one other where this has been asked and answered many times: http://www.jsworkshop.com/

good-luck.