Javascript Tutorials

Javascript Tip Boxes

Tip Boxes

Javascript Tip Boxes

When writing content for your site you might want to give some tips or explanations for particular words or phrases. For this you might consider using DHTML Tip boxes that appear when a link is rolled over. The following example shows how you can do this.

Example

Example of a link Tip Box


Rollover the link to see the Tip Box

Cut and Paste Code

Cut 'n' paste code for the above Example

JavaScript Code
HTML Code

Instructions Make a transparent gif called shim under your images folder as 'div' tag layers need an image to be present to work in Netscape plus we need it as a place holder (usually following the link) to show where the tip box should appear. If you are trying to use multiple tip boxes then you need to change the name of the respective div layer id field and also change the reference to it in the link onMouseOver event for the respective boxes. Also give the image place holder (here the shim image named imgDel) a new name property for each tip box and change the reference to it in the link onMouseOver event for the respective boxes.

Explanation of the Code

The java-script has the following main functions:

  • function showTipBox is used to make the tip box appear : This function first finds the top and left position of the place holder shim image (usually placed following the link) by its name passed to it while calling the function in the link onMouseOver event. Next it shows the div tag layer by the layer name passed to it by setting its visiblity property (to 'show' in Netscape and 'visible' in IE) and place it in the position of the place holder image.
  • function linkTimer is called to hide the tip box on the onMouseOut event after a small pause : This function waits for a small time period (here 500 milliseconds i.e. 1/2 a second) and then calls the hideLayer function (it passes the visible layer name).
  • function hideLayer is used to hide the visible tip box by setting the visibility property of the layer to 'hide' in Netscape and 'hidden' in IE.
Please like, +1, link to and share this SmartWebby resource if you found it helpful. Thanks!