Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > Usability

  • Print
  • + Share This
This chapter is from the book

Creating Fancy Rollovers

It's fairly common to have an image change when users mouse over it. Dreamweaver, of course, makes it easy to create this effect with the Swap Image behavior or the command Insert > Interactive Images > Rollover Image. But what if you want to change some text at the same time? You can do that, too, but it takes a little more work.

We'll first look at how to create an effect that changes two images when users mouse over a third image.

To change multiple images on a rollover:

  1. Create a new HTML page and save it.

  2. Insert an image onto the page.

    This image will be the hotspot for your rollover.

  3. Insert two more images onto the page. These images will change when users mouse over the first image.

  4. In the Property inspector, name the images you just added (Figure 13.32).

    Figure 13.32Figure 13.32 Name your images in the Property inspector.

  5. Select the hotspot image.

  6. In the Behaviors panel, click the + (plus) button and select Swap Image from the drop-down menu.

    The Swap Image dialog box will appear (Figure 13.33).

    Figure 13.33Figure 13.33 The Swap Image dialog box is pretty basic: Select any named image in the Images list box and then click Browse to set a new source for it. You can swap several images at once-the image that triggers this change is the one you had selected when you opened this dialog box.

  7. In the Images list box, select the name of one of the other two images.

  8. In the Set Source To file box, specify the file you want the image to change to.

  9. Repeat Steps 7 and 8 for the second target image.

  10. Click OK to close the dialog box.

  11. Preview the file in your browser.

    The second two images will change when the user mouses over the first one (Figure 13.34).

    Figure 13.34Figure 13.34 Ta-da! The rollovers work...sort of. When we mouse over the arrow, the smiley frowns, and the eyes turn into our coworker, Vlad. If you want Vlad to work elegantly, make sure the image being swapped in is the same size as the one it replaces.

You might have guessed that we're going to use the Change Property behavior we examined earlier to change the text. But this time we'll use the onMouseOver and onMouseOut events to trigger the behavior, instead of the onClick event we used before.

To change text at the same time as you change images:

  1. Add some text to the page from the previous example.

  2. Surround the text with a <span> tag (See To add a <span> to your page, earlier in this chapter). Make sure to add an id to the span tag.

  3. Select your hotspot image. In the Behaviors panel, click on the + (plus) button and choose Change Property.

  4. In the Change Property dialog box, select SPAN from the Type of Object drop-down menu.

  5. In the Named Object drop-down menu, select the named span you added to the page.

  6. From the Property drop-down menu, select innerHTML.

  7. In the New Value text box, enter the text you want to display when the user mouses over the image.

  8. Click OK to close the dialog box.

  9. In the Behaviors panel, click the down arrow next to the Change Property behavior and select onMouseOver.

  10. Repeat Steps 3 through 6.

  11. This time, in the New Value text box, enter the original text.

  12. Click OK to close the dialog box.

  13. In the Behaviors panel, click the down arrow next to the new Change Property behavior. This time, select onMouseOut from the drop-down menu.

  14. Preview the file.

    This time, the text will change with the roll-over along with the images (Figure 13.35).

    Figure 13.35Figure 13.35 The second behavior needs to be triggered on onMouseOut.

For more interesting ways to use rollovers, see Chapter 18, Toolbars, Tricks and Interactive Design.

  • + Share This
  • 🔖 Save To Your Account