View Full Version : My javascript picture handler needs tweaking...

11-10-2004, 05:06 PM
Hello all..

I got these 2 beautiful scripts from this site about 18 months ago, that allow me to show a photo gallery on screen that creates both small thumbnails and then blows up the photo to a set size. It works great....

But now, I've a need to a modification. I am now creating an "articles" gallery that will have .jpgs and .pdfs in it. Each should appear in the nice little rows and each when clicked must now open up to whatever size they ARE width wise with a scroll bar for height -- rather than my set sizes as per these two scripts...

<script language=Javascript type="text/Javascript">

function popImg(imageURL) {
var imgWin = window.open('about :blank','imgWin','width=200, height=200, left=100, top=100');

with (imgWin.document) {
writeln('<html><head><title>Articles Gallery</title>');
writeln('<style type="text/css"><!-- body { margin: 0px; } --></style></head>');
writeln('<body onload="self.focus();"><img id="pic" style="display:none" width="400" height="300" /></body></html>');
// set the width/height above to control how the pic is sized
var img = new Image();
img.onload = function() { sizeImgWin(imgWin, img) };
img.src = imageURL;

function sizeImgWin(win, img) {
var new_w = 400;
var new_h = 300;
// set the above numbers to be same as the writeIn line above to control
// how big the picture is blown up to...cool!
var old_w = win.innerWidth || win.document.body.offsetWidth;
var old_h = win.innerHeight || win.document.body.offsetHeight;
if (!new_w) { new_w = old_w; }
if (!new_h) { new_h = old_h; }
new_w -= old_w; new_h -= old_h;
win.document.title = img.src.substring(img.src.lastIndexOf("/")+1);
var pic = win.document.getElementById('pic');
pic.src = img.src;
pic.style.display = 'block';

Could someone show me how to do that? I realize that the vars new_w and new_h must be redone to instead "measure" the size of each article (they will be cut out of trade journals and newspapers etc.) for the display, but I can't figure out how to do this myownself....



11-10-2004, 07:50 PM
then does anyone know how to do this without using these functions, ie any other function?