Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
One of the most common interactive page elements is the ubiquitous image rollover. Dreamweaver's Swap Image behavior allows us to create image rollovers by selecting an image and choosing which image to replace it with when that image is interacted with. While this is normally used for image-based links, the Swap Image behavior is flexible enough to allow for some pretty cool creative exploration. In this movie, we're going to create an image gallery that relies on the Swap Image behavior to change a larger image when a thumbnail is selected.
This behavior is often called a disjointed rollover, where interacting with one image causes another image on the page to change. So I have the gallery.htm file open. If I scroll down it looks like our gallery is already finished. Well the layout is finished, so the CSS is finished and the structure of the gallery is put together. However, it is currently static, meaning if that we interact with it at all, nothing really happens. So our gallery is for the most part finished. We just need to add the interactivity now.
Next I am going to click on each of the thumbnails and one at a time, I am just going to call them thumb number one, thumb2, remember all one word, no spaces here, thumb3 and finally thumb4. So any time you're doing any type of an image rollover or Swap Image behavior, that's really step number one. You go in select the images that you want to affect and make sure that you give them a unique name. So all those names have to be unique. We could have just set thumbs for example for the thumbnails.
Okay, I am going to go ahead and select the first thumbnail image. This is the Golden Gate Bridge and although the larger Golden Gate Bridge photo is currently open, if somebody we're interacting with the other thumbnails, obviously we want to be able to bring that one back. So I am going to select that, I'll go over to my Behaviors panel. Now again, if you can't find your Behaviors panel, go up to Window and choose Behaviors. I am going to grab the plus symbol and I am going to go down to Swap Image right there. As Swap Image comes up, the wisdom of naming this image becomes readily apparent to us.
Notice that if we don't name them, they are just called unnamed and there is no way for us to know who is who. Now we don't want to swap the thumbnail image out. We want to change the larger photo. So I am going to make sure, I highlight image "photoLarge" and then all I have to do is browse it to the photo that I want to use. So I am going to select Browse, I am going to go into _images, and inside that we have a folder called gallery_interact. I am going to open that up and there are all my photos. Now I am going to change this to a detail view, because it's just going to be a little bit easier for me to scroll through this.
I am looking for this bridge_ large.jpg. So bridge_large. When I find that I am going to click OK and I am tempted to go and click OK again, but I have got a couple of other options here I need to talk about first. The first one is preload images. Anytime you are doing a Swap Image behavior, I recommend going ahead and preloading those images on the page. It'll prevent any type of image flicker when you rolled over image for the first time, or when you select an image for the first time. However, do be aware that preloading images means that all of the images in your gallery are going to be loaded as the page loads.
If you have a large image gallery, then that can dramatically slow down your page load time. I also want to deselect Restore images onMouseOut. When I mouse over the thumbnail and click on it, I want the image to show up. I don't want to bring the other image back once I mouse off of the thumbnail. I want that image to persist. So that's good. I am going to go ahead and click OK and I can see in my Tag Inspector there is my Swap Image behavior. Now notice that for the Swap Image behavior, the default action for that is onMouseOver. So somebody rolling over this thumbnail, for example, with the mouse.
That's not what we want. We want this image to only load if somebody clicks on the thumbnail. So I am going to grab that pull down menu right there and I am going to choose onClick. So now my behaviors says onClick, Swap Image and that is all there is to that. It is really that simple. I am going to go through each image and just repeat that process. So I am going to select the olives, grab the pulldown menu and choose Swap Image. Again, be very careful and make sure you're selecting image "photoLarge." We don't want to swap out the thumbnails.
For this one I am going to set the source to olive_large and again I am going to remember deselect Restore images onMouseOut. After I click OK, I am going to remember to change the action to onClick. I'll do the bird next. We'll go and select that, do Swap Image, again making sure that we are doing photoLarge, I am going to browse and find the bird_large, I am going to turn off Restore images onMouseOut and click OK, and then finally change onMouseOver to onClick.
You can get into a rhythm doing this, but it's also sometimes dangerous, because you get into that rhythm and you just start clicking and you kind of forget what you're doing. Your mind starts to wander if you have a lot of these thumbnails. So take your time, go slowly and focus. You want to make sure you going to get this right the first time. Let me go ahead and select the oranges thumbnail. Once again I am going to grab the pull-down menu and choose Swap Image, photoLarge, Browse and I want to do the oranges_large, click OK, turn off Restore images onMouseOut, and change that to onClick.
Now as I mentioned, you want to make sure you get this right the first time, but that's really just to save yourself the time and effort of having to go back and do it again. The nice thing about these behaviors is that once you set them, you can go back and edit them at any time. So if you do get one wrong, don't feel like you have to start this project all over again,. You can simply click to thumbnail, come over and double-click the Behavior itself and change anything that you need to change. Notice that there is a little asterisk beside photoLarge. That's telling you who is swapping out. You could swap out multiples if you wanted to, but if you saw that asterisk beside the thumbnail, you'd know something was wrong and you would just want to remove that and set it back for photoLarge.
Same thing for the trigger action. At anytime you can come and click that and choose any other action that you'd want. Now I am going to go ahead and save this file, and I am going to preview this in my browser. If I scroll down into the gallery now, as I click on these different thumbnails, my images are loading and I'm getting the image I expect. Awesome. Now the gallery's basic functionality is for the most part finished, but I want to point out something about these images. Notice that if you mouse over the image, your cursor doesn't change. it just stays as that arrow.
That's really not helping the user out at all. If somebody were just to browse over these thumbnails, they might think that they wouldn't be clickable because they're not getting any feedback from the browser. So what we are going to do next is go in to make a very simple change to the CSS. This is going to help us set some user expectations about these thumbnails. So I am going to close my browser and go back into Dreamweaver. Now anytime you're trying to access the CSS that's in a fairly complex section of code, the easiest way to do is through the Code Navigator. So what I am going to do is hold down my Alt key and if you are on the Mac you can hold down your Option and Command key and I am going to click on one of the thumbnails.
It does not matter which one. You'll notice that we have a rule that says #mainContent #photoGallery.thumb space img. So there's the image tag. That's we were looking for. I am going to go ahead and click on that and it's going to open that up in Split View. Now I am just going to hand code this, because this is incredibly easy to do. So go find this rule. Notice it's online 862 of the main CSS. I am just going to create a blank line at the end of this, making sure that I am staying inside of this curly braces, and I am going to type in cursor:pointer.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 103171 Viewers
58 Video lessons · 55753 Viewers
61 Video lessons · 89863 Viewers
56 Video lessons · 105024 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
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.
Your file was successfully uploaded.