jQuery LightBox Plugin

My favourite plugin! Mostly dedicated to pictures and galleries, this plugin is a zooming and animated tool, well designed and so practical for any demonstration purpose. Source and © Leandro Vieira Pinho.
  • Previous Resource
  • Download
  • Next Resource

Demonstration

LightBox and Images

Click here to open an image in a ligtbox

LightBox with galleries

How to setup

As usual, the first thing to do when you want to use a plugin is to include the required files in the header of your page.

For the LightBox, those files are first the jQuery library, then the plugin script, and an additional stylesheet:

  1. /** jQuery Inclusion **/
  2. <script type="text/javascript" src="Path_to/jQuery.js"></script>
  3. /** Plugin Inclusion **/
  4. <script type="text/javascript" src="Path_to/lightbox.js"></script>
  5. /** Additional Style **/
  6. <link href="Path_to/lightbox.css" rel="stylesheet" type="text/css" />

Then the next step is to declare how and when the LightBox will be displayed on your page.
The following code tells that every link that has a class LightBox will have its content opened in a LightBox.
It can be added in the page header or in a separate js file.

  1. <script type="text/javascript">
  2. $(document).ready(function(){
  3. $(".lightbox").lightBox();
  4. });
  5. </script>

According to what we\'ve just done, we then just need to create a link with a class LightBox and specify in its href attribute, what we would like to display in the LightBox:

  1. <a href="Path_to_target" class="lightbox">Test LightBox Plugin</a>

As we\'ve mentionned in the introduction, this plugin becomes very interesting when used with a gallery of images, not just a single one.

To obtain the result shown in the demonstration, we\'ll use a slightly different approach.
The idea is to group several links together in a container, and specify that all those links are in fact a gallery. So first, let\'s create this container and those links:

  1. <div id="gallery">
  2. <ul>
  3. <li><a href="image1.jpg"><img src="thumb_image1.jpg" /></a></li>
  4. <li><a href="image2.jpg"><img src="thumb_image2.jpg" /></a></li>
  5. <li><a href="image3.jpg"><img src="thumb_image3.jpg" /></a></li>
  6. <li><a href="image4.jpg"><img src="thumb_image4.jpg" /></a></li>
  7. <li><a href="image5.jpg"><img src="thumb_image5.jpg" /></a></li>
  8. </ul>
  9. </div>

Then, to setup up your gallery, you need to group all the links of the container div #gallery together in the javascript:

  1. $("#gallery a").lightBox();

Why not share this here:

  • Tweet this
  • Buy the author a coffee
  • Bump this
  • Digg this
  • Post this on Del.icio.us
  • Post this on StumbleUpon
  • Post this on Reddit
  • Post this on Technorati
  • Post this on Google
  • Post this on Facebook
  • Email this to a friend

You may also like:

  • How to create an Ajax, validated form
  • A guide to Ajax Interactions with jQuery
  • Slick Videos Presentation With Fancybox
  • jQuery Form Validation Plugin
  • jQuery FancyBox Plugin
  • jQuery ThickBox Plugin

Leave a Comment

Posted Comments

jdmweb
Il me semblait bien l'avoir reconnu sur ton site! J'espère que ça avance comme tu veux!
From jdmweb at 17:05 07/09/09 { Reply }
loic
Moi aussi c'est mon préféré!!! non sérieusement il est vraiment simple et offre un super bon rendu.
From loic at 16:40 07/09/09 { Reply }