|
||
DHTMLLib Demos/ Tooltips
Hover over the DHTMLLib Demo link above to see a demonstration of simple tooltips. These tooltips can be any HTML and are defined
directly on the link. To add a tooltip, you add an onmouseover event handler, include DHTMLLib, and the tooltip script.
First, let's show you how to define a tooltip on a link:
The tooltip is defined by setting the tip property on the window. The contents of the tip
property can be any HTML you desire. There is no need to add an onmouseout handler as that is detected
automatically through event bubbling. Below is the script that displays the tooltip:
The last step is to include a DIV element that displays the tooltip. This DIV element
is reused for all tooltips. A DIV element
is used over the TABLE element because we need to modify the positioned element's contents.
© 1998 by InsideDHTML.com, LLC. All rights reserved.
<A HREF="/writeOnce/writeOnce.asp"
ONMOUSEOVER="window.tip='All about cross-browser web-development'">
Write Once!
</A>
function showText() {
if (window.tip) {
var el = document.all.tooltip
el.style.pixelTop = window.event.clientY + document.body.scrollTop + 15
el.style.pixelLeft = window.event.clientX + document.body.scrollLeft + 8
el.innerHTML = window.tip
el.style.visibility = "visible"
}
}
function hideText() {
// Hide the tooltip
document.all.tooltip.style.visibility = "hidden"
window.tip = ""
}
function doLoad() {
setup()
window.document.onmouseover = showText
window.document.onmouseout = hideText
}
window.onload = doLoad;
<DIV
ID="tooltip"
STYLE="position: absolute; layer-background-color: yellow; background: yellow; visibility: hidden; width: 120px;">
</DIV>