spacer

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

home / experts / javascript / column16


Clearing a Tooltip

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


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

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