PDA

View Full Version : Java Help please! - Inmage sizing



mattyjb
27-09-2005, 08:52 PM
Hi, I have just been building up my site with a new layout which has a lot of graphics in it. I want the layout to size itself to the size of brwoser window so it doesnt mater what resolution a peroson is viewing the site at.
I found a neat piece of script which reloads the page each time the window is resized and in conjunction with that i used another piece that is supposed to to do what i want:
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ed Churnside -->
<!-- Web Site: http://www.dragonquest.com/inddpl.htm -->

<!-- Additional documention available online at -->
<!-- http://www.dragonquest.com/dplsspic.htm -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function showpic(src, w, h, alt, aln, pw, ph, bw, bh) {
if (src == null) return;
var iw, ih; // Set inner width and height
if (window.innerWidth == null) {
iw = document.body.clientWidth;
ih=document.body.clientHeight;
}
else {
iw = window.innerWidth;
ih = window.innerHeight;
}
if (w == null) w = iw;
if(h == null) h = ih;
if(alt == null) alt = "Picture";
if(aln == null) aln = "left";
if(pw == null) pw = 100;
if(ph == null) ph = 100;
if(bw == null) bw = 24;
if(bh == null) bh = 24;
var sw = Math.round((iw - bw) * pw / 100);
var sh = Math.round((ih - bh) * ph / 100);
if ((w * sh) / (h * sw) < 1) sw = Math.round(w * sh / h);
else sh = Math.round(h * sw / w);
document.write('<img src="'+src+'" alt="'+alt+'" width="'+sw+'" height="'+sh+'" align="'+aln+'">');
}
// End -->
</script>
</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

<BODY>

<script language="javascript">
showpic("crowd.gif", 362, 113, "A crows of people", "middle");
</script>

But the problem with this script is that it doesnt have a max size for the image so every image I use this script on is the width of the browser, this obviously stuffs up the site, does anyone know how to modify this so it has some sort ratio to it? I am pretty novice at this

thanks for any help
M@TT

Rob99
28-09-2005, 12:17 AM
<BODY>

<script language="javascript">
showpic("crowd.gif", 362, 113, "A crows of people", "middle", 50);
</script>
Note the 50 it will only go 50% the width.