Sams Teach Yourself HTML 4 in 24 Hours

Sams Teach Yourself HTML 4 in 24 Hours

By Dick Oliver

Learning How to Fly

For the first part of this hour, your noble quest will be to make some text "fly in" from the edge of a page when that page first comes up in the browser window. Just to make the quest more worthy of pursuit, you'd better make the text slide diagonally, instead of left to right. Naturally, what you really want (and shall no doubt soon gain) is a general-purpose script that you can use to slide any text or graphics any way you want.

While you're at it, why not go wild and ask for a script that can slip things underneath the edge of other things, or slide one layer of text and graphics behind or in front of any number of other layers?

Figures 20.1 and 20.2 are snapshots of a Dynamic HTML Web page with flying text. This is the xyzfiles.htm document you were just instructed to download from the 24-Hour HTML Café, so you may want to look at it on your computer screen now. See how the text glides in from behind the file folders as soon as you pull up the page? Pretty cool, huh?

20fig01.gif

Figure 20.1 Dynamic HTML lets you animate overlapping layers of text and graphics. This text is emerging from behind some images.

20fig02.gif

Figure 20.2 The text that was moving in Figure 20.1 has settled into place and stopped.

To achieve the effect shown in Figures 20.1 and 20.2, your HTML and JavaScript code needs to do all of the following:

  1. Check to make sure that the user's Web browser can handle Dynamic HTML and provide some alternative content if it can't.
  2. Define and name the layer containing the text; hide it out of sight beyond the edge of the page.
  3. Define and name the layers that contain the file tab images. (Each tab is actually assigned its own layer because later in this hour they are all animated separately.)
  4. Animate the text layer sliding onto the page.

Figure 20.3 shows the HTML that does all these things. The following sections explain how each of these four tasks is accomplished.

20fig03.gif

Figure 20.3 This is the HTML for the page in Figures 20.1 and 20.2. The JavaScript that does the animation is in a separate file (see Figure 20.6), named slide.js.

Share ThisShare This

Informit Network