http://www.chrispearson.org/pages/programming/javascript/scrolltip.asp
09h40
Wednesday, 8. October 2008

SCROLLING TEXT TOOLTIP

Like a lot of attractive JavaScript-powered functionality, this uses a few standard JavaScript techniques but combines them to create something beyond the usual. (Like a lot of JavaScript, a version is only as good as the browser for which it was developed - This one works with IE.) It combines action on the onMouseOver event of the web banner graphic with displaying a tooltip. In turn, the style of the tooltip is set to be a marquee - scrolling text.

The requirement for this kind of functionality came up in a web-based training application where we needed to display some large chunks of instructional text - Adding the marquee scroll is an embellishment (An embellishment too far? Maybe . . . )

The scripting is quite straightforward.

The tooltip is defined

    <div id="ourToolTip"
        style="position:absolute;
        visibility:hidden;
        clip:rect(0 150 50 0);
        width:150px;
        background-color:purple;
        z-index:10">
    </div>

Note that where the tooltip colour is defined, background-color:purple;, you can use background-color:none; which makes the tooltip transparent. It can be sized to match the volume of text to be displayed. The image is coded to react onMouseOver, passing a message string to the function which displays the tooltip

    <div align="CENTER"
        name="ourImage"
        onMouseover="DisplayTip(this,event,
           'www.chrispearson.org: The web site created by Chris Pearson');"
        onMouseout="HideTip();"
        STYLE="cursor: hand">
        <IMG SRC="../../../Images/sitename.gif"
           WIDTH="622" HEIGHT="76" BORDER="0">
    </div>

The tooltip display is achieved by script in the head of the HTML page, placing formatting and the text string into the tooltip's innerHTML.

The tooltip is switched off by the function hidetip(), called onMouseOut. See the source of this page for the full script, which does some, although not exactly comprehensive, browser-compatibility checks. (It doesn't work with Opera 6, for sure!)

Top of this page

xxx,xxx

copyright ©2000 - 2008 Chris Pearson