Dreamweaver Tutorial: Add a jQuery Lightbox to Dreamweaver websites
Learn How to Add a Lightbox to Adobe Dreamweaver CS5.5 Websites
In this tutorial, you will learn how to add the popular jQuery Lightbox function to a Dreamweaver webpage without using Code View.
What is the jQuery Lightbox?
In today’s internet, the slickest and most common method of displaying higher resolution images or featured images when a link to an image is clicked is to show a larger image overlaid above the entire webpage. The area surrounding the Lightbox image is typically grayed out to highlight the displayed image.
How does Lightbox look & function in a Dreamweaver website?
Below is an example to demonstrate the exact jQuery Lightbox that is constructed using this free Adobe Dreamweaver CS5.5 tutorial.
Step 1: Linking the Webpage with the jQuery Library
To begin, we must open an existing webpage or create a new one in Adobe Dreamweaver CS5.5. Once the page has been created and saved, download the jQuery library file and save it to a new folder within your project’s root folder called/js/
. To link the Dreamweaver webpage to this new javascript file, click the cursor into the Head Content Panel then go to the Insert panel and choose Common > Scripts > Script. Click the folder button and browse to your jQuery file, press ‘OK’.
Step 2: Add Custom Javascript to the Adobe Dreamweaver Webpage
To add javascript to the webpage directly, again click the cursor into the Head Content Panel then choose Insert > Scripts > Script. Instead of browsing to a file, place the cursor into the Content text area of the Script Window and paste the javascript (code) below.
jQuery(document).ready(function($) { $('.lightbox_trigger').click(function(e) { //prevent default action (hyperlink) e.preventDefault(); //Get clicked link href var image_href = $(this).attr("href"); /* If the lightbox window HTML already exists in document, change the img src to to match the href of whatever link was clicked If the lightbox window HTML doesn't exists, create it and insert it. (This will only happen the first time around) */ if ($('#lightbox').length > 0) { // #lightbox exists //place href as img src value $('#content_lightbox').html('<img src="' + image_href + '" />'); //show lightbox window - you could use .show('fast') for a transition $('#lightbox').show(); } else { //#lightbox does not exist - create and insert (runs 1st time only) //create HTML markup for lightbox window var lightbox = '<div id="lightbox">' + '<p>Click to close>/p>' + '<div id="content_lightbox">' + //insert clicked link's href into img src '<img src="' + image_href +'" />' + '</div>' + '</div>'; //insert lightbox HTML into page $('body').append(lightbox); } }); //Click anywhere on the page to get rid of lightbox window $('#lightbox').live('click', function() { //must use live, as the lightbox element is inserted into the DOM $('#lightbox').hide(); }); });
Step 3: Place Thumbnail Links into the Dreamweaver Webpage
To make this Lightbox work, there must be a hyperlink for each image that is to be displayed with Lightbox. Each of these links must have a class called lightbox_trigger
or they will not open the images with Lightbox. To add a class that is not in your style sheet, highlight each link individually then press Shift + F5
to open the Tag Editor window for a
. Select the Style Sheet/Accessibility tab and type the classlightbox_trigger
into the Class text field as shown below.
Step 4: Create CSS Rules to Display the Lightbox on the Dreamweaver Webpage
Using the CSS Styles panel on the right side of the Adobe Dreamweaver CS5.5, create three new rules relating to the lightbox div. These rules are called #lightbox
, #lightbox p
, and #lightbox img
. These can be customized to your liking, below I have listed the rules I recommend.
#lightbox
- position: fixed
- top: 0
- left: 0
- width: 100%
- height: 100%
- background: [save this overlay 1×1 pixel png image into the appropriate images sub-folder of the Dreamweaver website, then browse to it and set it as the repeating background image]
- text-align: center
#lightbox p
- text-align: right
- color: #FFFFFF [white]
- margin-right: 20px
- font-size: 12px
#lightbox img
- max-width: 940px [this will ensure that very wide images are displayed smaller to ensure they fit within the standard-sized browser window]
- max-height: 750px [prevents images that are too tall from being cut-off]
- Note: In the example above, there is a shadow applied to this CSS Rule. Dreamweaver does not yet support all the new CSS3 features, therefore to add the box-shadow effect one must manually add the CSS code into the
#lightbox img
rule. The shadow-box CSS rules are listed below. To access the necessary code, right click on the rule in the CSS Styles panel and choose “Go to code”, place the cursor onto a new line and enter the code below.box-shadow:0 0 25px #111;
-webkit-box-shadow:0 0 25px #111;
-moz-box-shadow:0 0 25px #111;
Dreamweaver Tutorial: Add a jQuery Lightbox to Dreamweaver websites
You can follow all the replies to this entry through the comments feed.
Leave a Reply
Featured Clients
Take the first step
Questions? Give us a ring, shoot us an email or send a homing pigeon our way. Let’s get the ball rolling! We can’t wait to hear from you!
Gecko Designs, LLC
523 N Higgins Ave
Missoula, MT 59802
Phone:
(406) 662-1123
Email:
Thank you this was very helpful.
followed these instructions to the letter and they are not working.
Byron, can you post a link to your code so I can help troubleshoot?
I did too it wont work properly for some reason
Mark, I’d like to take a look at your code. Can you post it somewhere so I can review?