Overriding the browser's default link behavior
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
Overriding the browser's default link behavior
Inside the ready, we're going to type function, beginning and ending parentheses, beginning and ending bracket. Then we are going to split the brackets. Anything happening inside of here is going to run after jQuery has downloaded all of the HTML code in the page. So, the first thing we want to do is start by targeting all of the anchor tags that are inside of the gallery thumbnails div. Start with the Dollar sign, beginning and ending parentheses, two tick marks for string literal.
I am going to type gallery_thumbnails space a, come outside of the parentheses .click, beginning and ending parentheses here, semicolon. Now, we are adding a click event to all of the anchor tags. Inside of here, we are going to type function, beginning and ending parentheses. Inside of the parentheses, we are going to put a lowercase e.
This is going to capture the event that actually started the click. Beginning and ending bracket and let's split this function. The first instruction inside of the function on the click event for every one of the anchor tags, we are going to type e.preventDefault, beginning and ending parentheses, and a semicolon. This tells the browser to ignore the default behavior that it would do on an anchor link, which in this case so far has been when we click on a thumbnail, the entire page shifts over to the high-resolution thumbnail.
So we are going to tell the browser to not do its basic function on an anchor tag. And then what we want to do is let's set the states of the thumbnails. So, let's start by copying the statement, come down here, Command+V or Ctrl+V to paste, so gallery_thumbnails a. We are going to go through all of these. I am going to type 'removeClass' and put a string literal inside of the parentheses, called selected.
We are going to make sure that none of the anchor tags have the selected class assigned to them. On the next line, let's paste that same statement again. We are going to say all of the anchor tags .children.CSS, beginning and ending parentheses, semicolon. Inside of here, we are going to do one string literal. We are going to type 'opacity' then a comma, then a second string literal and the number 1.
So, we are basically going to add CSS properties to all of the thumbnails, setting the children, the image tag inside of the anchor tag, with an opacity of 1. Add a few more lines. Then we are going to say Dollar sign parentheses, this, which is whatever the item is that was actually clicked on. We are going to say addClass, string literal, selected, and hit Return, Dollar sign this .Children.CSS, beginning and ending parentheses, semicolon, two tick marks for string literal opacity, two tick marks .4, for 40% opacity.
Let's say File > Save. Let's make sure all of our files are saved in Dreamweaver. Choose Save All. Then we are going to come out to the OS. We are going to grab this index file and open it up in a browser. Hit Reload. Now, when I roll over these items, I see the rollover state. When I click on them, whatever item I click on, the border turns white from the selected class we created earlier, and the image inside gets 40% transparent.
Now, with our thumbnails fully functional, let's start on the preview area.
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.