Creating a custom function for lightbox properties
Video: Creating a custom function for lightbox propertiesNow, the way Fancybox works to initiate links into the lightbox is to simply add classes on anchor tags and then set up a jQuery statement that looks for those anchor tags with specific classes. If I go into the includes directory, into Fancybox, they've included an index.html file. If I double-click this, this will give me a bunch of different examples on different ways the Lightbox can work. This one here just simply fades up and down. This one here runs an elastic animation up and down, giving us that zoom effect.
Viewers: in countries Watching now:
Download a copy of the finished web site here.
- Preparing gallery photos using Adobe Bridge
- Adding and linking thumbnail images
- Creating the layout in HTML and CSS
- Downloading and adding jQuery to the project
- Creating preview images from anchor links
- Implementing the preload functionality
- Building a customized lightbox with the Fancybox plug-in
- Styling the zoom and contact links
Creating a custom function for lightbox properties
Now, the way Fancybox works to initiate links into the lightbox is to simply add classes on anchor tags and then set up a jQuery statement that looks for those anchor tags with specific classes. If I go into the includes directory, into Fancybox, they've included an index.html file. If I double-click this, this will give me a bunch of different examples on different ways the Lightbox can work. This one here just simply fades up and down. This one here runs an elastic animation up and down, giving us that zoom effect.
This one just sort of pops on and pops off. We can also do different things with the captions. We can have captions show up underneath. We can have captions show up inside the border. And the one I like, the last one here, I can actually have the text show up inside a semi-transparent overlay. And in order to see how all of these are coded, we can take that index file and open it up in either a text editor or Dreamweaver. So at the very top here, I can see here are the different examples, and lower in the code, we can see how they are executed.
That's the name of the function. We can name this anything we want. Beginning and ending parentheses, beginning and ending bracket. I am going to hit a few returns. Now inside of here, I am going to tab in. We're going to make a jQuery statement, Dollar sign, beginning and ending parentheses, two tick marks for string literal, a.overlayLink, come outside of here, .fancybox, beginning and ending parentheses, then a semicolon.
Then inside this function, we're simply going to put just two brackets-- beginning and ending. We're going to split that open. Let's come inside here, and let's set some of the parameters. I am going to do two tick marks for a string literal. We're going to do titlePosition, space, colon, another string literal, the word over, this will place the text over top of the overlay. Let's tab in. This is going to be 'overlayColor', colon, string literal, '#000'--that's black.
Next line, string literal 'overlayOpacity' : 0.8, 80%, put a comma. Next line, type 'transitionOut', string literal, 'elastic', comma. Next line, 'transitionIn'. I just realized I spelled the first transition incorrectly.
'transitionIn', also 'elastic', then a comma. The last line we're going to turn 'autoScale': to true. Now in the last one, we don't need a comma because these are paired values, but the very last one doesn't need a comma because there's nothing that's going to be repeating after that. So now this function, setFancyboxLinks, is going to run.
It's going to find every anchor tag with the overlay link class assigned to it, and it's going to activate it as a Fancybox link. So now we need to actually initiate this function. So let's copy this. Let's scroll up. Let's come up here into the area where we are preloading the image and then setting all of the content inside both the preview and the caption. So let's come in here after we say gallery_preview.fadeIn, gallery_caption.fadeIn. Let's add another line. Then we're simply going to put setFancyboxLinks with the beginning and ending parentheses and a semicolon.
This is going to call this function. Now the last thing I need to do, let's come down and select overlay link. Let's copy that to the clipboard, Command+C or Ctrl+C, and we need to come up here and add this class into these two links. So this first one here, gallery_preview, let's put a space inside the anchor tag, class equals, two quotes, paste in overlay link. And then down here, we have our text base link which says view larger. Let's add the same class in here, class="overlayLink".
So now these two anchor tags are going to get dynamically written in. Then we're going to fade up all the content. Then we're going to run the setFancybox function. This function is going to then go back through the document, look for every anchor tag with overlay link, and it's going to find these two that we just created, and then it's just going to activate these on click to overlay the image and it's going to link it to the full-size photo, which is the href of the original anchor tag. In addition, the caption is going to come from the title tag in the anchor tag. Let's choose File > Save.
Let's go over to our operating system, and let's open up index.html in our browser. Once it opens, we will hit Command+R or Ctrl+R to Reload, click on an image. The image fades up, caption fades in, I click on the image. This initiates the lightbox. I see the full screen image. I also see the caption down here, Caption for refraction goes here. Now in the lightbox, I can actually click anywhere; I don't have to hit just on the X. It zooms back into place. Click on another photo, come down and click on the View Larger Text.
Now, notice that the image, if we use the Elastic setting, will create the elastic zoom based on the actual link. So the text link down here, the image will be really tiny, autoscale down to the size of the text link, and then zoom up. So now that this functionality is working perfectly, in the next movie, we're going to add another custom function for the update thumbnails, and then we're going to be able to set up a function that's going to autostart the gallery. So when we first load it, it will automatically highlight the first picture, set the thumbnail, and set the caption.
Find answers to the most frequently asked questions about Create an Interactive Photo Gallery with jQuery and Dreamweaver .
Here are the FAQs that matched your search "" :
- Q: The finished state of the interactive photo gallery in this course shows a clickable preview. When you click on the preview image, or on the view larger icon, a larger lightbox image appears. Chris's example has a close button and border surronding the large image, but mine doesn't. Did I miss a step?
- A: The functionality you describe is part of FancyBox plug-in we use in this course. It's a custom lightbox tool, which I've included in the exercise files and also available for download at fancybox.net. It's free and highly customizable.
By default, FancyBox adds a border to images (at least in the version of FancyBox we're using), but there are many options that can be turned on when you set up your fancybox initialization script, including the close button, which is invoked using the showCloseButton property. This is all covered in the "Creating a custom function for lightbox properties" movie.
If you want to customize your gallery further, look at the list of the customizable properties at http://fancybox.net/api.
- Q: This course was updated in April, 2013. What changed?
- A: Since the release of this course, Internet Explorer 9 and 10 have been released, and sometimes these browsers do not activate interactive HTML content. To remedy this problem, the author has added a movie to Chapter 10 that will show you how to:
- Update the HTML to HTML5
- Update the version of jQuery
- Use the Google html5shiv to keep compatibility with Internet Explorer 7 & 8
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.