Lightbox FAQ - 2007-05-07 20:18

What is Lightbox?

It’s a script that allows images to pop-up above a website. It’s a nice little javascript that makes pop-ups more pleasing. Visit huddletogether.com to see examples and to download the code. If this FAQ has been helpful or if you have emailed me and have found my help donation-worthy, donate away. The amount is up to you. Please know that I am in no way affiliated with the creation of Lightbox. I just help people who have a hard time understanding how to get it up and running.

Lightbox FAQ Topics:
How do you install Lightbox 2.0?
Is there a limit to the size an image can be?
How do I get the overlay to stretch over the entire window?
How do I create a gallery of images?
Is there a way to have one picture lead to a gallery of a lot of pictures?
How do I add a caption to the images?
How do I fix the broken loading images?
How do I make the previous and next buttons always show instead of just showing up when hovering?

How do you install Lightbox 2.0?

Download lightbox 2.0 from huddletogether.com.

Change the name of the downloaded folder from “lightbox2.02 Folder” to “lightbox”. Upload this folder to the root directory on your server.

Add the following code to the head of the html page you want to use lightbox on.
<script type="text/javascript" src="lightbox/js/prototype.js"></script> <script type="text/javascript" src="lightbox/js/scriptaculous.js?load=effects"> </script> <script type="text/javascript" src="lightbox/js/lightbox.js"></script> <link rel="stylesheet" href="lightbox/css/lightbox.css" type="text/css" media="screen" />

You may need to change the paths to make sure they point to where you have put the files. I use absolute paths, like:
http://zollinhofer.com/lightbox/js/prototype.js. To make sure that you have set your paths correctly, type whatever you have as the path above into the address bar of your favorite browser. If the file shows up, you did it correctly. If not, try again or shoot me an email and I’ll help you get it set up.

You will most likely need to go into your lightbox.js file and change the paths to the loading.gif and close.gif. You can find these near the top under “configuration”. Again, you can use an absolute path, or just set it to: “lightbox/images/loading.gif” & “lightbox/images/closelabel.gif”.

To make an image use Lightbox, you need to add rel=“lightbox” to the link. So this:
<a href="http://zollinhofer.com/images/picture1.jpg"> First Picture</a>
Would become:
<a href="http://zollinhofer.com/images/picture1.jpg" rel="lightbox">First Picture</a>

To make a group of pictures add rel=“lightbox[nameofset]” to the link. Add this tag to every picture that you want to be a part of the set.

Is there a limit to the size an image can be?

No, there is no limit, but the bigger an image is (filesize), the longer it takes to load. Also, the bigger an image is (height & width), you may end up having to scroll to see all of it. I manually crop my pictures to around 400 × 600 (at the biggest) so that I know if fits on the screen (and the filesize is reduced). If you don’t want to bother with manually cropping, you can check out the thread about A Solution For Large Images on the huddletogether forum (which discusses how to apply an extra piece of code that will resize the image for you).

How do I get the overlay to stretch over the entire window?

For some reason, there is a bit of a oversight in the lightbox.js code. You can do one of two things to fix this…

#1. Download my lightbox.js file and replace your lightbox.js with mine.

#2. Fix the file yourself. Open up lightbox.js and search for “this.showImage();”. You should see a line that has
this.showImage();
Add the following code right after that code:
var pageSize = getPageSize(); if((imgHeight + 150) > pageSize [1]) Element.setHeight('overlay', imgHeight + 300);
So the code should now look like:
this.showImage(); var pageSize = getPageSize(); if((imgHeight + 150) > pageSize [1]) Element.setHeight('overlay', imgHeight + 300);

How do I create a gallery of images?

Begin with the markup for your pictures. I’m going to use 4 pictures for my example.
<a href="http://yoursite.com/images/picture1.jpg" rel="lightbox">My first picture</a><a href="http://yoursite.com/images/picture2.jpg" rel="lightbox">My second picture</a><a href="http://yoursite.com/images/picture3.jpg" rel="lightbox">My third picture</a><a href="http://yoursite.com/images/picture4.jpg" rel="lightbox">My fourth picture</a>

You then need to change the rel=“lightbox” to rel=“lightbox[nameofgallery]”.
<a href="http://yoursite.com/images/picture1.jpg" rel="lightbox[mygallery]">My first picture</a><a href="http://yoursite.com/images/picture2.jpg" rel="lightbox[mygallery]">My second picture</a><a href="http://yoursite.com/images/picture3.jpg" rel="lightbox[mygallery]">My third picture</a><a href="http://yoursite.com/images/picture4.jpg" rel="lightbox[mygallery]">My fourth picture</a>

Is there a way to have one picture lead to a gallery of a lot of pictures?

Sure. There are two easy ways to do this.

1. Give each one of the images an extra class (I use the class “hide”) except for the very first image which you don’t want to hide. I’ll use the same example as above:

<a href="http://yoursite.com/images/picture1.jpg" rel="lightbox[mygallery]" title="Picture 1">My first picture</a><a href="http://yoursite.com/images/picture2.jpg" rel="lightbox[mygallery]" class="hide" title="Picture 2">My second picture</a><a href="http://yoursite.com/images/picture3.jpg" rel="lightbox[mygallery]" class="hide" title="Picture 3">My third picture</a><a href="http://yoursite.com/images/picture4.jpg" rel="lightbox[mygallery]" class="hide" title="Picture 4">My fourth picture</a>

I’ve added class=“hide” to the 2nd, 3rd, and 4th images. You will need to add the class “hide” to your css file as well. Open up the lightbox.css file and add the following code:

.hide { display: none; }

This way the only image I’ll see on the page is the first one. The others will be hidden. This way is the most accessible.

The second way is to leave the text for the link blank, so there is nothing to click. This way is not quite as good because if for some reason the user has javascript disabled, they won’t be able to get to those pictures. But this is how you would do it if you chose to go that route:

<a href="http://yoursite.com/images/picture1.jpg" rel="lightbox[mygallery]" title="Picture 1">My first picture</a><a href="http://yoursite.com/images/picture2.jpg" rel="lightbox[mygallery]" title="Picture 2"></a><a href="http://yoursite.com/images/picture3.jpg" rel="lightbox[mygallery]" title="Picture 3"></a><a href="http://yoursite.com/images/picture4.jpg" rel="lightbox[mygallery]" title="Picture 4"></a>

How do I add a caption to the images?

It is quite easy to add a caption to an image. You should start with the regular markup for an image:
<a href="http://yoursite.com/images/picture1.jpg" rel="lightbox">My first picture</a>
All you have to do is add a title to the image…
<a href="http://yoursite.com/images/picture1.jpg" rel="lightbox" title="Whatever little phrase you want your caption to be">My first picture</a>
That’s it!

How do I fix the broken loading images?

For some reason, the original lightbox.js file has the wrong paths. You’ll need to go into the file and fix the paths under configurations (which is directly under the table of contents). I used absolute paths for mine.
var fileLoadingImage = "http://zollinhofer.com/lightbox/images/loading.gif"; var fileBottomNavCloseImage = "http://zollinhofer.com/lightbox/images/closelabel.gif";

If you set the paths correctly, you should be able to type the path into your browser and the image should show up. If you installed lightbox in the method I explained above, your path should be similar to mine (with your site’s name where zollinhofer.com is).

How do I make the previous and next buttons always show instead of just showing up when hovering?

All you have to do is go into the lightbox.css file and change a few lines. Find the id for prevLink & nextLink as you see below:

#prevLink:hover, #prevLink:visited:hover { background: url(../images/prevlabel.gif) 0 15% no-repeat; border: none; } #nextLink:hover, #nextLink:visited:hover { background: url(../images/nextlabel.gif) 100% 15% no-repeat;
border: none;
}

and change it to this:

#prevLink, #prevLink:hover, #prevLink:visited:hover { background: url(../images/prevlabel.gif) 0 15% no-repeat; border: none; } #nextLink, #nextLink:hover, #nextLink:visited:hover { background: url(../images/nextlabel.gif) 100% 15% no-repeat;
border: none;
}


Posted by Truitt on Oct 18, 10:40 PM

this is so good.

Posted by rxbbx on Oct 19, 04:59 AM

I want to use it for my doggies gallery.. thnx for your little tutorial.. its good..

anyhow.. how about bigger pictures.. is there a limit.. which size would you prefer

Regards

Robert

Posted by Brian on Oct 19, 11:26 AM

Addressed above. Let me know of any other questions you feel should be added to the FAQ.

Posted by Terry N on Oct 19, 10:59 PM

Also I am pleased to find that Litebox and Im sure Lightbox 2.0 is fully compatible with Internet Explorer 7, the newest version just released in its ‘final’ version.

Posted by Brian on Oct 20, 11:18 AM

Terry, that is good to hear. I hope that IE7 handles all the things it messed up in IE6. Like standards.

Posted by melissa on Oct 20, 04:50 PM

I cant seem to get the captions to work on my lightboz.. can you help??

Posted by Brian on Oct 20, 10:00 PM

No worries Melissa. I hope the answer in the FAQ help!

Posted by Truitt on Oct 23, 08:59 AM

is it just me, or is this post multiplying?
like…it is longer each time i check it.

Posted by Brian on Oct 23, 09:07 AM

That’s right baby! It’s an FAQ… I’ve got to add content when someone asks a question frequently… :)

Posted by Dave Porter on Oct 29, 01:38 AM

Hi thanks for the great support for lightbox.
I’ve seen lightbox in use around the traps but never knew what it was….

Also just letting you know your link to the huddletogether site ( love that name ! ) at the top of the page links to the zip file ! Just might confuse some folk.
cheers, Dave

Posted by Val on Oct 31, 07:11 AM

Hi !

I have a problem and does not find any solution for it : lightbox does not work under IE for Mac.
Even when I apply the solution you offer by adding …;initLightbox() to the onload, the image opens up in a new page. It works on every browser but IE… What’s wrong?

Thanks for helping

VM

Posted by Tracy Harris on Oct 31, 07:25 PM

Hi!

Thanks for supporting lightbox! I hope you can help me with the problem I am having. The overlay will not stretch to the bottom of the browser window in IE. I have tried changing the body margin and padding to zero, and I also changed the lightbox.js file to match yours, but it is still not working. There must be something that I am doing wrong. Any help you can give would be much appreciated. Thanks!

Tracy

Posted by TheWorldIsMean on Oct 31, 11:06 PM

I’d love to hear what you have to say. Please be respectful and use appropriate language as this is a student-friendly site. Otherwise, I’ll hunt you down, rip out your eyelashes, and poke you in the eye with them. The left one.
That wasn’t very respectful or appropriate…

Posted by Dekard on Nov 1, 06:14 AM

IE for MAC isn’t even supported from MS since January of 2005, I would probably switch browsers seeing how they aren’t fixing the holes in the IE for Mac browser. :(

Posted by Brian on Nov 1, 08:56 AM

The World Is Mean: Yes, I know… But I work with middle schoolers and this is the type of humor they can deal with…

Val: Dekard is right on. Microsoft doesn’t support IE for Mac anymore. If they don’t feel their program is worth supporting, neither do I. People who are using a Mac shouldn’t be using IE. They (as a collective whole) are smarter than that. Firefox and Safari work so much better and play nicely with others. Not so much with IE. So I don’t know if there is a fix (it is doubtful there is), but I wouldn’t put the time or effort into since Mac users shouldn’t be using IE anyway. The Mac should be taken away and given to someone else who can use it more sensibly. Much like a 60” plasma and a blind person. No offense to any blind people reading this… I’m sure they would agree with me. They would probably enjoy a nice stereo system more…

Tracy: if you could shoot me an email with the URL of the site, I could take a look and see what is happening. There are probably some paths set wrong or some styles that are conflicting…

Posted by Marcus Bellon on Nov 1, 07:51 PM

I still cannot get this thing to work. What could I be doing wrong?

Posted by Jorge Ranilla on Nov 3, 12:48 AM

I’ve been all over the Drupal forum and this forum looking for the answer to this….Where do I place the rel=”lightbox” so that all “view original” image module links open with Lightbox. Seems I’m not the only one with this question but it seems as though when someone asks the thread ends there. hahaha.

I read somewhere that the cvs version does this automatically but I don’t see that option under settings/lightbox2.

I’m on day three of trying to figure this out and its getting frustrating as you could imagine. If anyone could point me in the right direction that would be great.

Thanks in advance,
Jorge Ranilla

Posted by Anna on Nov 4, 07:37 PM

I am working with this script locally on my computer. I have 6 images in a single gallery for one section and only 3 images work in the gallery with the next/prev links. I’ve checked everything over about 8 times or so and restored all files back to default to try again and I still get the same result. Any suggestions?

Posted by Anna on Nov 4, 07:41 PM

Nevermind. 2 seconds later, I fixed it. LOL I downloaded your lightbox.js file and it seems to work now. Odd.

Posted by Frits de Beer on Nov 6, 11:09 AM

How can we disable “animation” in lightbox 2

Posted by Mackula on Nov 7, 01:54 PM

I’m getting broken images for the closelabel and loading gif. Everything else is fine. Also this doesn’t happen on my local machine, just when uploaded.

Page on:
http://www22.addr.com/~mackula/gambit/gallery1a.html

Any help appreciated

Posted by Brian on Nov 7, 03:02 PM

Frits: I don’t know how to disable animation. Sorry.

Mackula: I just posted an answer to that under broken loading.gif

Posted by Paul on Nov 9, 08:26 AM

Hi! Is there any way to put some HTML (i.e. DIV with some infos) in the captions?
thx,
Paul

Posted by Claire on Nov 12, 05:24 PM

Hey,

I’m sure these instructions make perfect sense to some, but i just cant get my head around them! This is the first time I’ve designed a site and so I don’t really know where/what code goes in. Just contacting really to find ou if you are able to give me specific (basic!!)advice if i send across the html code for my page etc….? Thanks for your time, Claire x

Posted by Robert on Nov 14, 11:25 PM

I am having difficulty with the lightbox. My flash menu shows through the overlay. Even though the div that contains the nav.swf file’s z-index is set to “0” and the flash movie is set to
wmode=”transparent”. Here is the url to my site.

www.metaphiziks.com

If you could help it would be great.

Rob

Posted by Kathy Kinney on Nov 15, 03:47 PM

With the help of your tutorial I finally got Lightbox to work! I am so excited and thankful to you for walking a “newbie” like myself through it! The only issue I am having is I can’t get the captions to work. If you go to http://www.kpea.org/test/education2.htm (which is a site totally “in progress”) and try either the North America or Africa thumbnail, lightbox should work—- but no caption. Any help?
Kathy

Posted by Brian on Nov 15, 09:04 PM

Robert: Sorry, but I don’t know anything about flash. I wish I could help.

Kathy: Your captions are showing up, but the color of your text is white, making it look like your captions aren’t showing up. Change your text color in the css file and it should be all set!

Claire (and others): I’m always happy to help in any way possible. Just shoot me an email and let me know what I can do!

Posted by Lesley on May 11, 12:17 PM

Hi Brian, I just wanted to say thank you soooo much for putting these instructions up here. There is no way I would have ever have got lightbox to work without them on the website I’m building. Thank you. :-)

Posted by Michael Burton on May 13, 10:34 PM

Thanks for your help. Now I will learn more from your site and that will be quite a lot. This is only the beginning of my learning from a true teacher. Thanks Once Again.

Posted by Brian on May 17, 05:54 PM

I’m glad you have all found it helpful. Please let me know if there is anything you would like to see me add.