The Enhanced Lightbox is a jQuery plugin that allows designers and developers to overlay single images and/or image collections in a webpage, using very little extra markup.
This plugin is an extension of Leandro Vieira's jQuery Lightbox, to which I added a few features I wanted, like the ability to add titles and descriptions to each image (using HTML5 data-* attributes), the option to fit large images to the browser window, and better lightbox positioning. I used these features quite a lot in this website, check for instance the Design Scrapbook.
I hope you find it useful. Enjoy!
jQuery Enhanced Lightbox
Instructions and Examples
Setting up
First of all, you'll need to include the jQuery library and the Enhanced Lightbox Javascript and CSS files in your HTML header, like this:
Obviously, you'll need to adjust the paths if you place the files somewhere else. You'll also probably want to load jQuery via a CDN instead of hosting it yourself, in which case change that first line to this, which will use Google's:
Usage
Calling the lightbox is as easy as setting a HTML link to the image, like this:
However, that won't work just yet! You need to bind the lightbox to whatever jQuery selectors you want to be lightbox-able. So you need to embed a bit of Javascript at the end of your document to do just that. Some examples (beware of case sensitivity):
That last example will bind one lightbox to each set of links inside a photoset class. That allows you to have multiple galleries inside the same page, so that clicking for the next/previous image in a lightbox won't take you to another gallery. Here's an HTML example of that:
Which will produce something like this:
Collection 1
Collection 2
Please note how both sets are independent.
More options
Adding a title to each image is as easy as setting its link's title attribute:
You can also add a short text underneath the title by using the HTML5-compatible data-info attribute:
Here's a set of images with titles and descriptions:
By default, big images will be resized in order to fit the browser window, and a magnifying glass will appear when you hover the center of the image, allowing you to see it at 100% zoom. This behaviour makes sense when the thumbnails users first clicked on are quite small and the resized lightbox image is much bigger already.
However, if the 'thumbnail' is an image embedded in a blog post and pretty big already, that kind of behaviour is just stupid (you risk having your users getting a smaller image in the lightbox). So you set the data-maximized attribute with the value always in order to stop it:
That'll force the lightbox to forget about its resize-and-zoom powers, and just show the image at the original size. Compare the two examples (you may need to resize your browser window if it is too tall):
Advanced
A bunch of advanced options may also be set by editing the variables at the begining of the jquery-enlightbox.js script.You can change the location of the lightbox's UI images, the "Image X of Y" text, the lightbox's overlay color, etc. Alternatively, you may set those variables when binding the lightbox to jQuery selectors. Here's an example (again, be careful about case sensitivity):
These will change the overlay's background color and opacity, the speed at which resizing occurs, and the Image X of Y text. Read the start of jquery-enlightbox.js for the variables you may set.







