xTooltipGroup Demo

Tested on Win2K with Opera 7.23, Mozilla 1.5, and IE 4, 5 & 6.

xTooltipGroup provides for multiple groups of tooltips. For each group you create two style classes. One is applied to all elements which will trigger the tooltip. The other specifies the tooltip style for the group. The tooltip takes its text from the element's TITLE attribute - or you provide an array of strings.

There are four different tooltip groups on this demo page: Group 1, Group 2, Group 3, and Group 4. Tooltip size and styling is controlled by the tipClass argument. Tooltip positioning is controlled by the origin and offset arguments.

The xTooltipGroup Object

Syntax

new xTooltipGroup(grpClassOrIdList, tipClass, origin, xOffset, yOffset, textList)

Parameters

grpClassOrIdList - The css class name which you add to any element you want to trigger a tooltip - Or - an array of id strings.

tipClass - The css class name applied to the tooltip triggered by elements with the grpClass class name (or elements whose id is in the IdList).

origin - One of 'right', 'top', or 'mouse'. For 'right' or 'top', the tooltip is positioned to the right (or top) of the trigger element. For 'mouse' the tooltip will follow the mouse. In all three cases the following offsets are applied.

xOffset, yOffset - The tooltip is positioned relative to the above origin, offset by these amounts.

textList - If grpClassOrIdList is an array of IDs, then textList provides the tooltip text for the corresponding array index. If grpClassOrIdList is a class name then textList is not needed (tooltip text is taken from the element's TITLE attribute).

Usage

The following shows how the four tooltip groups on this page are initialized.

window.onload = function()
{
  new xTooltipGroup('tipGrp1', 'tipGrp1s', 'right', 4, 0);
  new xTooltipGroup('tipGrp2', 'tipGrp2s', 'top', 0, -2);
  new xTooltipGroup('tipGrp3', 'tipGrp3s', 'mouse', 20, -10);
  new xTooltipGroup(['p0','p1','p2','p3', 'p4','p5'],
                    'tipGrp4s', 'right', 4, 0,
                    ["<p><b>heading</b></p><p>text</p>",
                    "<p><b>heading</b></p><p>text</p>",
                    "<p><b>heading</b></p><p>text</p>",
                    "<p><b>heading</b></p><p>text</p>",
                    "<p><b>heading</b></p><p>text</p>",
                    "<p><b>heading</b></p><p>text</p>"]);
}

Over 2000+ free Javascript
at JavaScriptBank.com Website

Revisions

v2.01, 1Mar04, Now works in IE 4 and 5. Used document.write instead of document.createElement.

v2.00, 13Dec03, Almost completely rewritten. Now supports html for tooltip text instead of using the title attribute.

v1.01, 12Dec03, Correction for when the mouse moves directly from one trigger element to another.

v1.00, 11Dec03, Initial release.