Create an Interactive Photo Gallery with jQuery and Dreamweaver
Illustration by John Hersey

Changing the preview when clicking thumbnails


From:

Create an Interactive Photo Gallery with jQuery and Dreamweaver

with Chris Converse

Video: Changing the preview when clicking thumbnails

Now that we have our preview links set up in our CSS, let's come over to our JavaScript file. So now what we want to do is create those anchor links based on the image thumbnail that was already selected. So, let's add a few lines into our JavaScript file, and the first thing we are going to do is set up a few variables. We are going to type 'var photo_caption', and that's going to equal Dollar sign, this .attr, semicolon, and then inside there a string literal, title.
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 28s
    6. Adding CSS properties for content area
      4m 0s
    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 40s
    1. Activating a gallery automatically in IE9 and IE10
      2m 40s
  11. 2m 43s
    1. Some ideas for further enhancements
      2m 43s

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course Create an Interactive Photo Gallery with jQuery and Dreamweaver
1h 55m Intermediate Apr 27, 2011

Viewers: in countries Watching now:

In Create an Interactive Photo Gallery with jQuery and Dreamweaver, author Chris Converse develops an interactive photo gallery for a web site using HTML, CSS, and the open-source JavaScript library jQuery. The course begins with tutorials on extracting different-sized images sets from an original photo collection, designing the site layout, and constructing the HTML and CSS. Then, following the progressive enhancement strategy, Chris utilizes JavaScript plug-ins to include lightboxes and other types of interactivity while maintaining backwards compatibility with older browsers and devices. Exercise files accompany the course.

Download a copy of the finished web site here.

Topics include:
  • 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
Subjects:
Developer Photography Web
Software:
Dreamweaver jQuery
Author:
Chris Converse

Changing the preview when clicking thumbnails

Now that we have our preview links set up in our CSS, let's come over to our JavaScript file. So now what we want to do is create those anchor links based on the image thumbnail that was already selected. So, let's add a few lines into our JavaScript file, and the first thing we are going to do is set up a few variables. We are going to type 'var photo_caption', and that's going to equal Dollar sign, this .attr, semicolon, and then inside there a string literal, title.

So, whichever anchor link we actually clicked on, we are going to pull into a new variable called photo_caption the title attribute of that object. That's going to give us our caption. var photo_fullsize. It's going to be equal Dollar sign this .attr, and in here we are going to put href, the actual link destination of full size, because we took the thumbnail images and actually linked them to the high-resolution full-size image.

That's where that variable is going to set up. Then lastly, photo_preview. Now, photo_preview would never use the term preview.jpg. So right now in our HTML, there is no way for the browser to know we specifically will have another file size here called preview. So, what we are going to do is concatenate this by string replacing the file name fullsize with the file name preview. So, in order to do that, we are going to grab photo_fullsize, copy this, so photo_preview is going to equal photo_ fullsize.replace, beginning and ending parentheses, semicolon.

Now, this is not a jQuery function. This is a straight JavaScript function. We are going to put inside of replace two tick marks for string literal, fullsize, comma, two more ticks for another string literal, preview. So, this is very similar to what we did in Bridge when we were doing our grep search for our file name replacement. So, we are basically coming in here and saying photo_preview is going to equal the full-size variable, which we got from this line here and is going to search for fullsize and replace it with _preview.

That's going to give us the URL to the preview image. Now, on the next line, we are going to actually write the HTML into the page. Dollar sign, tick mark, gallery_preview.html, beginning and ending parentheses, semicolon. Inside of the HTML tag, we are going to put two tick marks for string literal, and we are actually going to write the anchor tag we are going to create.

So, beginning tag a space href =. I am going to put to two full quote marks. I am going to end the tag and then end a tag. Inside the href, I am going to put an x for the moment. Let's add another attribute, title equals two quotes, another x, style equals background-image:url beginning and ending parentheses, semicolon, and let's put an x inside there as well.

Now in places in this string literal where we have Xs, we are going to replace these with the variables. So, let's start with photo_caption. Let's grab this and copy to the clipboard. Let's come down to title. Let's delete the x. Let's put two single tick marks, two Plus signs, and then let's paste the variable inside of there. So, what happens here is we get a concatenation of the string literal and the variables that we set. So, the first part of the statement comes right up to the two tick marks here.

Then JavaScript we will replace in photo_caption, and then we will get the rest of the statement. So, for the href, we want to take photo_fullsize, copy that, two tick marks, two Plus signs, paste that in. That means that the preview image is going to actually link to the full-size image. So, instead of the thumbnails linking there, we have prevented that default; instead, we are going to have the preview anchor link to show the image in the background. Then later on, we are actually going to add the lightbox link to this as well.

Then lastly, let's come over and grab photo_preview. This is the preview JPEG url. Let's come over to the x in the image url, two ticks, two Plus signs. Then we will paste that in. Let's choose File > Save. Let's make all of our files inside of Dreamweaver are saved. Choose File > Save All. Let's come back to our operating system. Let's grab the index.html file, double-click it, Command+R or Ctrl+R to reload.

And now when I click on each of these images, I see that the image will actually update over on the right-hand side. Again, this is just an anchor link with the background style. And of course, if I roll over it, we can see the pop- up window coming in for the title. So, that works great! In the next movie, we are we are going to actually pick up the caption, and we will populate the caption to go along with the photo.

Find answers to the most frequently asked questions about Create an Interactive Photo Gallery with jQuery and Dreamweaver .


Expand all | Collapse all
please wait ...
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
 
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

* Estimated file size

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 ?

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 preferences from 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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

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.