How To Fly Text in DHTML
How To Fly Text in DHTML
How To Fly Text in DHTML
<MARQUEE behavior=slide>
<UL>
</UL>
</MARQUEE>
... DIRECTION="left">
<UL>
</UL>
</MARQUEE>
3. Specify all other appropriate attributes to control flying speed and
number of times to scroll.
Click the following Show Me button to see a flying text sample that
uses the marquee element. The sample is from a slide show
presentation and works best on an 800 x 600 display, with a full-
screen browser window.
Show Me
Implementing the preceding steps in a page causes text to fly as
soon as the page comes up. (Click the Show Me button above to see
how this works.) However, this might not always be appropriate,
because sometimes you might want to make the text fly on demand
—for example, on a mouse click or on a timer, as in a slide show
presentation. The way to do this is through the marquee object's
start and stop methods, as illustrated in the following code.
<SCRIPT>
function window.onload()
function document.onclick()
</SCRIPT>
It is best to do this with the rest of the elements laid out on the
page, so that you can visualize where everything fits. This can be
done with the help of style sheets. The following sample defines a
global style sheet with a style element, specifying the fonts, colors,
and margins to be used.
1. Hide Example
2. <STYLE>
3. <!--
4. :
7. margin-left:0.5in; margin-right:0.5in;
8. }
9. :
10. -->
11. </STYLE>
12.
With the style sheet defined above, the following sample uses
relative positioning—the text is positioned somewhere near the
element's position in the document (that is, to the left, right, top, or
bottom). The sample uses a div element and sets the appropriate
CSS attributes for the text block. Note that the visibility property is
initially set to hidden, so that the text is not visible until flown in.
(This might not be necessary in every case, although it is
recommended.)
</DIV>
The following sample flies the first block of text vertically, from the
top down, and calculates the initial y-coordinate position for the
element as shown below. For more information about how to access
the dimension and location of elements on the page through the
document object model, see Measuring Element Dimension and
Location.
Text1.style.pixelTop = document.body.offsetTop
- Text1.offsetTop
- Text1.offsetHeight;
</SCRIPT>
Text1.style.visibility= "visible";
5. Fly the text in, adjusting the pixelTop or the pixelLeft property for
flying top to bottom or left to right, respectively.
The following function takes a pointer to the object being flown and
also a stop value. The stop value indicates the pixelTop value at
which flying stops.
Show Example
Click the following Show Me button to see a flying text example that
uses dynamic positioning. The sample is derived from a slide show
presentation and works best on an 800 x 600 display, with a full-
screen browser window.
Show Me
Related Topics