View Full Version : Image Thumbnail Viewer II

10-21-2005, 04:26 PM

Is it possible to have a caption under the big pictures show up on rollover of the thumbnail?

If not, I could always use alternate text for the images, but it would be a cool effect to have the caption show up under a pic.

Edit: on second thought, I'm not sure how to add alternate text in this script. :confused:

10-21-2005, 06:08 PM
Sure, to enable a caption for a particular image, simply replace the code of Step 1 for the script with:

<script type="text/javascript">

* Image Thumbnail Viewer II script- Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use

//Specify image paths and optional link (set link to "" for no link):
var dynimages=new Array()
dynimages[0]=["photo1.jpg", "http://www.cnn.com", "This is a caption"]
dynimages[1]=["photo2.jpg", "http://www.yahoo.com"]
dynimages[2]=["photo3.jpg", "http://www.google.com"]

//Preload images ("yes" or "no"):
var preloadimg="no"

//Set optional link target to be added to all images with a link:
var optlinktarget=""

//Set image border width
var imgborderwidth=0

//Optionally, change 1.0 and 0.7 below to affect Wipe gradient size and duration in seconds in IE5.5+:
var filterstring="progid:DXImageTransform.Microsoft.GradientWipe(GradientSize=1.0 Duration=0.7)"

///////No need to edit beyond here/////

if (preloadimg=="yes"){
for (x=0; x<dynimages.length; x++){
var myimage=new Image()

function returnimgcode(theimg){
var imghtml=""
if (theimg[1]!="")
imghtml='<a href="'+theimg[1]+'" target="'+optlinktarget+'">'
imghtml+='<img src="'+theimg[0]+'" border="'+imgborderwidth+'">'
if (theimg[1]!="")
if (typeof theimg[2]!="undefined")
imghtml+='<br />'+theimg[2]
return imghtml

function modifyimage(loadarea, imgindex){
if (document.getElementById){
var imgobj=document.getElementById(loadarea)
if (imgobj.filters && window.createPopup){
if (imgobj.filters && window.createPopup)
return false


The first image has a caption.

10-21-2005, 08:25 PM
That works GREAT, thanks!

Reference for future users of the forum:

This part:

<div id="dynloadarea" style="width:350px;height:420px"></div>

Has to be adjusted for greater height to accomodate the extra space taken up by the caption.

12-13-2005, 07:14 PM
Is there a way to change the font size of the caption?

12-13-2005, 07:41 PM
Is there a way to change the font size of the caption?

Sure, the same ways you would any text. To change all the captions, you can use style in the head:

<style type="text/css">
#dynloadarea {

12-20-2005, 05:53 PM
Hi, is there a way to make it so each time a mouse is over the thumb nail, a highlighted border will show up. Very much like this
Thank you.

12-20-2005, 09:28 PM
Yes, it will depend upon how you have things set up and upon the size of your thumbnails, easiest if they are all the same size. Put a style section in the head of your page, something like this:

<style type="text/css">
.thumb {
margin:5px 5px 0 0;
border:1px solid #dedede;

.thumb:hover {
border:1px solid black;

The only really important thing is the width. Set it to the width of the thumbnails. If the thumbnails vary in width it will need to be set inline for each one's anchor tag. Now, in the markup for the thumbnails (loosely from the demo), you can use:

<a href="#" class="thumb" onMouseover="modifyimage('dynloadarea', 0)"><img src="thumb1.jpg" width="50" height="50" border="0"></a>