Create Drop-Down Stickies

Create Drop-Down Stickies

Use DHTML to position sticky drop-down windows relative to keywords in your HTML.

Attaching a drop-down sticky to a word or phrase in your document is an easy way to add valuable information close to the word, without obscuring it. That way, the user can click on the word and get more contextual information, all without scrolling or lots of mouse movement.

The Code

Save the code in Figure as index.php.

PHP and JavaScript cooperate to make drop-down stickies work
$nextid = 1;
function start_link( $text )
  global $nextid;
  $idtext = "a"+$nextid;

?><a href="javascript: void drop( '<?php echo($idtext); ?>' );">
	<span id="a_<?php echo($idtext); ?>"><?php echo($text); ?></span></a>
	<div id="<?php echo($idtext); ?>" class="drop" style="visibility:hidden;">
<table cellspacing="0" cellpadding="0" width="170"><tr>
<td valign="top" width="20">
<a href="javascript: void close(<?php echo($idtext); ?>)"><img src="close.gif"
<td valign="top" width="150">

function end_link( )

function link_header( )
<style type="text/css">
body { font-family: arial, verdana; }
.drop {
  padding: 5px;
  font-size: small;
  background: #eee;
  border: 1px solid black;
  position: absolute;
<script language="Javascript">
function drop( sid )
  aobj = document.getElementById( "a_"+sid );
  divobj = document.getElementById( sid ); = aobj.offsetBottom+10; = aobj.offsetLeft+10; = "visible";
function close( sid )
  divobj = document.getElementById( sid ); = "hidden";

<?php link_header( ); ?>
Hey <?php start_link( "this is interesting" ); ?>
That really<br/>
Is interesting <?php end_link( ); ?>. How about that.
The popup will go over text and all that.<br/>
And it will stay up until it's dismissed with the close

The script defines three functions at the top of the file: start_link, end_link, and link_header. The call to start_link takes the text of the link as an argument. The contents of the drop-down box are then supplied, and the end_link call is made.

To get the CSS classes and JavaScript into the header, you need to call the link_header function within the head tag.

Running the Hack

Copy the code and the images to the server. Point your browser to the index.php script and you will see something similar to Figure.

A clickable keyword in the document

Now click on the link and you will get the drop-down box with a close icon, as shown in Figure.

See Also

The drop down positioned under the link

 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows