Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Creating a custom function for lightbox properties

From: Create an Interactive Photo Gallery with jQuery and Dreamweaver

Video: 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.

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.

So this is an anchor tag with an ID of example 1. So example 1 is the one that just simply fades up and fades down. I'll come up to the top of the document. I'll look for example 1, which is right here, and that's just the simple Fancybox statement. Other ones here have a bunch of different settings: overlay, transitionIn, transitionOut, opacity settings, positioning for the captions, a whole bunch of different formats--and of course, the web site documents all of these different switches. So what we're going to do is go into our JavaScript file, and one of the things that we'll also need to do is typically we assign the anchor tags to be paid attention to by Fancybox by putting it in the document ready.

However, since we are going to be pulling HTML from one spot and concatenating the data into the caption area, we need to be able to reinitiate all of the links. So what we're going to do is create a brand-new function outside of the document ready in our JavaScript file and run the Update Overlay links any time we're going to make a change. So we're going to start by coming to the bottom of the document here outside of the document ready, and we're going to create our own custom function. I am going to type 'function', and we're going to call this setFancyboxLinks.

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.

Show transcript

This video is part of

Expand all | Collapse all
  1. 7m 51s
    1. Previewing the project across browsers and devices
      5m 32s
    2. About the exercise files
      2m 19s
  2. 9m 49s
    1. Renaming a series of files in Adobe Bridge
      3m 7s
    2. Using GREP for more intricate file renaming
      6m 42s
  3. 29m 5s
    1. Creating and linking HTML and CSS files
      1m 32s
    2. Save For Web & Devices in Photoshop
      7m 2s
    3. Creating empty CSS rules
      3m 55s
    4. Create, nest, and class DIV tags
      6m 0s
    5. Adding CSS properties for main container
      4m 0s
    6. Adding CSS properties for content area
      4m 28s
    7. Adding CSS properties for headings
      2m 8s
  4. 15m 55s
    1. Adding and linking the thumbnail images
      2m 32s
    2. Styling the thumbnail links with CSS
      5m 15s
    3. Downloading and adding jQuery to your project
      2m 42s
    4. Overriding the browser's default link behavior
      5m 26s
  5. 11m 10s
    1. Creating preview images from anchor links
      1m 52s
    2. Changing the preview when clicking thumbnails
      5m 59s
    3. Changing the caption when clicking thumbnails
      3m 19s
  6. 12m 0s
    1. Adding an image preload plug-in for jQuery
      2m 22s
    2. Setting a dissolve transition between previews
      4m 31s
    3. Implementing the preload functionality
      5m 7s
  7. 15m 20s
    1. Adding a lightbox plug-in for jQuery
      2m 2s
    2. Creating a custom function for lightbox properties
      7m 38s
    3. Setting links to activate the lightbox feature
      5m 40s
  8. 3m 40s
    1. Initializing the gallery on page load
      3m 40s
  9. 5m 11s
    1. Adding icons and styles to the zoom and contact links
      5m 11s
  10. 2m 41s
    1. Activating a gallery automatically in IE9 and IE10
      2m 41s
  11. 2m 43s
    1. Some ideas for further enhancements
      2m 43s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Create an Interactive Photo Gallery with jQuery and Dreamweaver.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.