Full service digital strategy planning and implementation.
April 1 2011
I have been spending the last couple of days re-writing our lightbox script. Our original lightbox script simply opened the selected photo, and closed it again with a click. Since then, the script has been heavily modified with numerous hacks to add a whole range of new functionality. It all works, but the script has become extremely messy, so I decided to re-write it completely. This would provide us with a clean script, and allow me to add a couple of new features as well.
To use the script, simply include the script on the page with a standard script tag. Some of the functions I’ve used are included in other script files (eg: common functions), so we have to include those as well. If we need to change the default settings, add another script tag with the new settings. Then for each link that should open in a lightbox, use the following attributes:
To cater for xhtml compliance, the title can also be used to pass a complete set of settings, including the contents of the non-standard attributes. To do this, simply create a javascript object string with the names and values of all your variables. If the object includes a title variable, the title attribute will contain this new title; otherwise the object string will be removed. The caption will be made up of all the variables in the object, except the system variables (title,width,height,vcode).
<a href=”path/to/my/file.jpg” rel=”lightbox_gallery1” rev=”image” title=”{title:’my file’,artist:’my artist’,price:’R250 each’}”>link</a>
The script is not quite ready yet. I am still working on ways to make the animation work properly on all the browsers. When I have the whole thing finished completely, I will post a more technical description of how it works, and I’ll include the script as well, so you can use it, abuse it, and let me know how to improve it.