PDA

View Full Version : Need help with image loading


shashgo
09-22-2002, 08:30 PM
hello all,

I have a bunch of images on my hard drive and I want to use javascript to load all of them without me having to specify each one. I also want to display them as thumbnails on a web page and then have an image open up in a pop up frame when the user clicks on a particular thumbnail.
The number of images is not fixed, as I will be adding new images every so often.

How do I do this?

martin_narg
09-23-2002, 08:00 AM
You cannot do this without using what is called an ActiveX object (in fact it's the FileSystemObject). If you wish to do this, all users will have a dirty great big "this could be dangerous, are you sure you wan to do this" message!

Sorry to be the bearer of bad tidings

m_n

umm
09-23-2002, 09:24 AM
This might help.
You have to name your images in a particular manner. They be like this format:
For thumbnails:
img_1_tmb.jpg
img_2_tmb.jpg
img_3_tmb.jpg
...etc.
For fullsized images:
img_1_full.jpg
img_2_full.jpg
img_3_full.jpg

Each thumbnail must correspond with it's full sized counterpart. For example, tht thumbnail called img_1_tmb.jpg corresponds with img_1_full.jpg.

The only thing you need to change in the script is the value for the variable called numberOfImages, to reflect the number of images you want to load onto the page. In the script example below, that is set to 2 because i tested with 2 images.

This script assumes you have the images placed in a directory called "images'. and that the normal path to reference an image would be "images/img_1_tmb.jpg" You can alter the path by changing the pth="images/" value to suit your own. All the images need to be in the same directory.

See how it goes anyway.


<html>
<head>
<title></title>
<script language="javascript" type="text/javascript">
<!--
function outputImages(){
var thumbsArray=new Array()
var fullSizeArray=new Array()
var pth="images/"
var printOut=""
var numberOfImages=2 //change this

printOut+="<table width=\"40%\" align=\"center\" border=\"1\">"
for(i=0;i<numberOfImages;i++){
thumbsArray[i]=new Image()
thumbsArray[i].src=pth+"img_"+(i+1)+"_tmb.jpg"
fullSizeArray[i]=new Image()
fullSizeArray[i].src=pth+"img_"+(i+1)+"_full.jpg"
printOut+="<tr><td><a href=\"javascript: void window.open('"+fullSizeArray[i].src+"','','width=300,height=300')\">"
printOut+="<img src=\""+thumbsArray[i].src+"\" border=\"0\"></a></td></tr>"
}
printOut+="</table>"
document.write(printOut)
}
// -->
</script>
</head>
<body>
<div style="text-align:center;">
<h1>Image Collection</h1>
</div>
<script language="javascript" type="text/javascript">
outputImages()
</script>
</body>
</html>