29/01 2007

Lightbox JavaScript

Lightbox javascriptFor my first post I thought i’d point out a fantastic little script i’ve discovered after reading the a4uforum. The Lightbox 2 code lets users popup a very cool image browser. To check it out take a look on the lightbox website and grab the download .zip archive.

Here’s how you implement it on your website.

1 - Setup
Lightbox v2.0 uses the Prototype Framework and Scriptaculous Effects Library. You will need to include these three Javascript files in your header.
<script type=”text/javascript” src=”js/prototype.js” mce_src=”js/prototype.js” ></script>
<script type=”text/javascript” src=”js/scriptaculous.js?load=effects” mce_src=”js/scriptaculous.js?load=effects” ></script>
<script type=”text/javascript” src=”js/lightbox.js” mce_src=”js/lightbox.js” ></script>

Include the Lightbox CSS file (or append your active stylesheet with the Lightbox styles).
<link rel=”stylesheet” href=”css/lightbox.css” mce_href=”css/lightbox.css” type=”text/css” media=”screen” />

Check the CSS and make sure the referenced prev.gif and next.gif files are in the right location. Also, make sure the loading.gif and close.gif files as referenced near the top of the lightbox.js file are in the right location.

2 - Activate
Add a rel=”lightbox” attribute to any link tag to activate the lightbox. For example:
<a href=”images/image-1.jpg” mce_href=”images/image-1.jpg” rel=”lightbox” title=”my caption”>image #1</a>

Optional: Use the title attribute if you want to show a caption.
If you have a set of related images that you would like to group, follow step one but additionally include a group name between square brackets in the rel attribute. For example:
<a href=”images/image-1.jpg” mce_href=”images/image-1.jpg” rel=”lightbox[roadtrip]“>image #1</a>
<a href=”images/image-2.jpg” mce_href=”images/image-2.jpg” rel=”lightbox[roadtrip]“>image #2</a>
<a href=”images/image-3.jpg” mce_href=”images/image-3.jpg” rel=”lightbox[roadtrip]“>image #3</a>

Adds a professional touch to any website.

Tom

back me up

No replies to “Lightbox JavaScript”