spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column16


Clearing a Tooltip

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

When the user removes the mouse from a tooltip-enabled link, the link's onMouseOut event handler calls the clearEl() function (with no arguments). For example:

<A HREF="/js/" onMouseOver="activateEl('javascript', event)"
  onMouseOut="clearEl()">javascript</A>

Let's take a look at the body of the clearEl() function:

function clearEl() {
  if (!style) return;
  var whichEl = (NS4) ? document[active] : -->
document.all[active].style;
  whichEl.visibility = (NS4) ? "hide" : "hidden";
  active = null;
  if (timerID) clearTimeout(timerID);
  if (NS4) document.releaseEvents(Event.MOUSEMOVE);
  document.onmousemove = null;
}

As in activateEl(), the first statement terminates the function if stylesheets are disabled. We must install this statement at the beginning of all functions that are called by event handlers.

The second statement, as explained in the previous section, assigns a reference of the desired object to a local variable. This is a short and simple way to create cross-browser references.

The next statement hides the current tooltip by assigning the corresponding value to the element's visibility property. For Navigator, the correct string is "hide" while Explorer expects the string "hidden".

The moment the tooltip is cleared, there is no active tooltip, so active is set to null. If a timeout is currently running, the clearTimeout() method is called to clear it. Let's assume the user moves the mouse over a tooltip-enabled link, and then removes it, without waiting enough time for the tooltip to display. Since the document.onmousemove event handler is disabled, checkEl() isn't called anymore, so the most recent timeout remains active. The displayEl() function is scheduled to run in another 300 milliseconds, so the timeout must be cleared.

Finally, the function dismantles the document's onmousemove event handler, because no tooltip is currently active; that is, the pointer isn't positioned over one of the page's tooltip-enabled links.

The next page lists the entire code for this technique. Be sure to continue reading after you take a look at the script, because we'll show you how to display these tooltips without having to explicitly add event handlers to each link.

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Created: March 26, 1998
Revised: March 26, 1998

URL: http://www.webreference.com/js/column16/clear.html