Hovertips - easy and elegant tooltips

Submitted by dave on Tue, 2006-08-22 07:40.

The text shown in italics are examples of hovertips. Move your mouse over the italic text to see what happens.

Text like this appears when you hover. And disappears after you move your mouse away.

This is an example of a hovertip.

What's a hovertip?

A hovertip is a kind of "tooltip" that appears when the mouse rests above something.

I call them "hover" tips to distinguish them from clicktips. Click your mouse over underlined italics to see a clicktip.

What's a clicktip?

A clicktip is also a tooltip. But unlike a hovertip, the user must press the mouse button to see one.

The clicktip text appears on the page, rather than floating beneath the mouse.

And the text remains visible until unti the user clicks a second time.

A single page can have any number of these things.

More Tricks

Both types of tooltip can contain arbitrary HTML. This means you can control their appearance with CSS stylesheets. You can include images, titles, etc. You can even include nested tooltips (click to see an example).

Nested Tips One

This clicktip includes both a nested clicktip and a nested hovertip.

This is a clicktip within a clicktip.

Nested Tips Two

And this hovertipa hovertip within a hovertip looks like this also has a nested clicktip.

Not bad, eh?

These are by no means the first tooltips ever written. But two things make them especially nice. The first is how easy they are to author. The second how easy they are to style.

How to Add Tooltips

The plugin includes several ways to markup tips, including:

<div>This is something you can click on to make a tooltip appear</div>
<div class="clicktip">This is the HTML that will appear when clicked.</div>
or,
<div>Hover hear to make a tooltip appear beneath mouse</div>
<span class="hovertip">This is the HTML that will appear on mouseover.</span>
The preceding code works when the tooltip immediately follows the element it is linked to. You can get more refined tooltip placement by using the id attribute:
<p>You can click <span clicktip="t1">here</span> or
<span clicktip="t1"> there</span>.</p>
<p> blah blah blah more HTML here blah blah blah</p>
<div class="clicktip" id="t1">
This is the HTML that will appear when clicked.</div>

How to style tooltips

Because the contents of the tooltips are arbitrary html, you can use stylesheets as you would any other content.

Simple, easy, elegant!

The script that makes all this possible relies on jQuery. Now that is a script that really makes things possible!

jQuery rocks!

I'm the newest member of the jQuery fan club!

And Still More Tricks

The hovertip plugin is quite flexible. With a little javascript, you can customize which nodes become the tooltips and which targets activate them. As a little demonstration, I've abbreviated all the comments below. To read the comments, click on the titles and the text will expand. Its using the same engine that drives the clicktips above. If the comments have the 'new' tag next to them, I don't collapse them. Something like this would be handy for returning to long threads and quickly seeing only the posts you haven't seen before.

All the necessary javascript is embedded in this post. So this is the only page on my site with this behavior.

Download

If you're not using Drupal, you may download the hovertip source code here. Otherwise, the hovertip module for Drupal is your best bet.


login or register to post comments


zorder question

Submitted by Anonymous on Tue, 2006-08-22 17:21.

When I click on the clicktip and then hover over the hovertip embedded therein, the hovertip's zorder is inverted such that it rests behind the clicktip. I can make the hovertip visible by reducing the size of the font, for a brief second or two. Firefox 1.5.0.6. Also tried with IE 6.0.2800.1106. Same result.

Still, way cool.

Mike Anon (drupal777 on drupal.org)


login or register to post comments


Hey thanks for pointing that

Submitted by dave on Tue, 2006-08-22 17:52.

Hey thanks for pointing that out.

The z-index was correct on the hovertip, but I added a wrapper (for drop shadow effect) and neglected to put the z-order on that. Fixed now.


login or register to post comments


great options

Submitted by ari on Tue, 2006-08-22 22:29.

It's great to have the option of click vs hover and of the result being inline vs floating.

would it be easy to have the hovertip inline and the clicktip floating?


login or register to post comments


Yes, it would be easy to

Submitted by dave on Thu, 2006-08-24 22:55.

Yes, it would be easy to make that change. You could modify the javascript slightly and not modify your HTML at all to change the behavior.

For those who know a little javascript, you can modify the behavior in all sorts of ways. There's some documentation in the hovertip plugin for jQuery.


login or register to post comments


XHTML valid

Submitted by Anonymous on Tue, 2006-09-05 13:48.

Would be cool if you can do it without non-standard (x)html-params (like hovertip or target) ;)


login or register to post comments


Can be valid

Submitted by dave on Tue, 2006-09-05 18:29.

You can. For example,

<div class="container"><div>This is the text</div><div class="hovertip">This is the tooltip</div></div>
 

This works as long as the tooltip immediately follows the text it applies to. The non-standard attributes allow you to place the tooltips elsewhere in the document. If you have better alternatives for that mark-up please let me know.


login or register to post comments


Drupal module?

Submitted by gaele@drupal.org on Mon, 2006-10-09 12:13.

Hey, thanks for this great plugin. I used it to present a complex diagram in a simple way (not public yet).
How far is your hovertips drupal module from being finished? I would be very much interested. It seems in 4.7 jquery conflicts with Drupal javascript functions (e.g. the input format link in the add comment section.)


login or register to post comments


Now a drupal module

Submitted by dave on Mon, 2007-01-15 02:37.

Hovertip is now a drupal module for drupal version 5. It is possible to use the plugin on drupal 4.7 (as this site does), but it requires a patch to drupal core. If anyone needs this I can provide more detail.


login or register to post comments


hiding hovertips' divs before "blocking" them

Submitted by peroksid on Thu, 2006-11-23 14:37.

On my pages hovertip divs appear after calling hovertipInit function all simultaneously for about second or half.
I tried to mess with JS (your script is very clean and easy to understand, almost first JS I really liked to read) but no luck, they hanged a little then hided.
I believe this effect appeared because jQuery takes much time on hide() after css('display', 'block') in jQuery.fn.hovertipActivate().
Manual hiding and showing of divs could not help too, so I put all hovertips divs in divs with style="display: none".

<div style="display: none;">
  <div class="hovertip">
    ..
  </div>
</div>
 

This works because you take that divs from their places and append them to body as I undertand.
Anyway it helped.
I dont know if you, dave, faced with such problem. Maybe It is just my specific case because I have very heavy pages here now.
But probably you could wrap hovertip in such a div before assigning hovertip's "display" css property "block" value to avoid such situation at all.


login or register to post comments


I recommend solving this

Submitted by dave on Sun, 2006-11-26 20:32.

I recommend solving this problem not with an extra div, but by hiding the hovertips in css. The javascript will unhide them at the right moment. If the user has javascript disabled, they will never appear. I include something like this in my .css file:
.hovertip {
    display: none; /* in case javascript is disabled */
    /* you can add additional style attributes here */
}

login or register to post comments


This way does not work for

Submitted by peroksid on Mon, 2006-11-27 15:46.

This way does not work for me(and for someone else probably too) - I told.
When you say css('display', 'block') jQuery unhides hovertips and they will be hided only after hide() chained with css().
This sounds strange, but time interval between displaying and hiding is big enough in my case to notify hovertips appearing from nowhere and then hiding.


login or register to post comments


z-index

Submitted by peroksid on Fri, 2006-11-24 13:15.

I have to show hovertips divs upon another elements wich have z-index set to 20.
I set z-index to div.hovertip to 60.
Hovertips continue to show under elements with z-index 20.
I changed hovertipShowUnderMouse function, added
'z-index': 60
after 'left': hovertipMouseX + 'px',
and hovertips became to appear where needed.

Cant understand how jQuery removes z-index from div.hovertip, but it probably does does.


login or register to post comments


Hovertip explorer targetSelectByPrevious problem

Submitted by michel on Fri, 2006-12-29 07:45.

Hello all,
I use this clean work to implement a kind of "new tip":a popupmenu, therefore a tip that appears with a click and disapears like an hovertip.
I'll post the necessary routines when it will be clean enough....

BTW, when I did test the hovertip under IE, the "targetSelectByPrevious" way doesn't work. Since I usually work on a mac, I dont have the necessary tools to investigate....

Thanks for the work anyway.
Michel


login or register to post comments


display and delay

Submitted by federico on Mon, 2007-02-05 11:24.

Hi and congratulations for this great plug-in.

I have one comment and one issue. the comment is that, as someone has alredy mentioned, I need to enclose the hovertip between a <div style="display:none;"></div> in order to avoid the tip to briefly displayed before diasspearing as the page loads up. this is not an issue for me as I am using the hovertip in a controlled enviroment where I know that js will always be turned on.

the issue I have is that the solution seems to work fine when one uses a small numebr of hover tips. I have inserted a hovertip in a table which is generated by a recordset. I use the unique ID from the recordset record to assign the various hovertip IDs. When the number of record is higher than 5/10 then the page becomes stuck for up to 1 or 2 minutes while, i suppose, the scripts deals with all the hovertips.

i supposed i must point out that i am using another plug-in (TABLE SORTER) which loads ok before hovertip scripts kick in.

Is this a limit of this hovertip plug-in, or is there something i am doing wrong?

many thanks,

Federico


login or register to post comments


I think the issue of whether

Submitted by dave on Mon, 2007-02-05 13:35.

I think the issue of whether the tips appear momentarily is browser-specific. What are you using?

The issue of how long the plugin takes to start up is a performance issue that depends on a number of things, including your machine and how large your page is and how many tip appear on it. As the page gets larger the delay will be more noticable as the script takes longer to find all tips.

If you take a look at hovertipInit(), you'll see that it handles several different ways of tagging the tips. If you know you are only using one or two, you can change this function to do only what you need it to do, and that will hopefully speed things up.


login or register to post comments


Yes, the DISPLAY issue is

Submitted by federico on Mon, 2007-02-05 15:34.

Yes, the DISPLAY issue is certainly browswer-specific. The problem is with IE 6 (not tested onIE7 yet). However, as I have to use IE, the extra div is inevitable.

As for the delay, since i only use one type of tooltip with no fancy FX, i have stripped the script down to its bare minimum and now the page loads in a acceptable timeframe.

thank you very much for the promt feedback.

Federico


login or register to post comments


Consider adding your extra

Submitted by dave on Mon, 2007-02-05 17:58.

Consider adding your extra div using javascript, instead of placing it there manually. I don't know if that works for IE, just a thought.


login or register to post comments


Getting the same results in IE6

Submitted by jonathanfreeman on Tue, 2007-03-06 19:47.

Hi,

We are getting the same results in IE6. We have a few hundred row cells that are using the tooltip with tablesorter. We have implemented the hovertip with: <span>target</span><span class="hovertip">blah blah</span> There is a very visible delay. We even have the .hovertip selector in css displaying to none, still produces the delay.

Also 2 odd things, we have tried to pack the plugin for performance, put it throws an error. And having a space between the above span's throws an error as well: <span>target</span> <span class="hovertip">blah blah</span>


login or register to post comments


Ajax hovertips

Submitted by Gorkfu on Thu, 2007-03-08 01:37.

Has anyone added ajax functionality into hovertips?


login or register to post comments


There is at least one other

Submitted by dave on Fri, 2007-03-09 06:03.

There is at least one other jquery plugin that is like hovertip, but using ajax to populate the tip. I don't recall it's name offhand, but I'm sure you could find it.


login or register to post comments


How inicializate the hovertips

Submitted by alexanmtz on Fri, 2007-03-30 15:28.

Hi, Im tryin to setup the hover tipo, but only with markut doesnt work... How I inicialize it???


login or register to post comments


positioning of hover and release.

Submitted by djdarkbeat on Mon, 2007-05-14 23:02.

// show the tooltip under the mouse.
// Introduce a delay, so tip appears only if cursor rests on target for more than an instant.
hovertipShowUnderMouse = function(el) {
hovertipHideCancel(el);
if (!hovertipIsVisible(el)) {
el.ht.showing = // keep reference to timer
window.setTimeout(function() {
el.ht.tip.css({
'position':'absolute',
'top': (hovertipMouseY - 140) + 'px',
'left': (hovertipMouseX - 120) + 'px'})
.show();
}, el.ht.config.showDelay);
}
};

I've positioned these to show the tip above and to the left of the statement but my off hover still seems to recognize where the box "would have been" when I leave. Specifically, it's treating the mouse cursor as if it's still to the right of the box when I try to leave. If I leave to the left of the element it closes immediately, if I leave to the right of the element it takes that 140 again before I can "mouse out".

Any ideas on where to set this or make the adjustment somewhere else in the script?

-B


login or register to post comments


Not sure why this is

Submitted by dave on Tue, 2007-05-15 00:54.

Not sure why this is happening, but possibly you are adjusting the top and left of the tip, but not the element containing the tip. And the hover behavior might be attached to that parent element. Take a look at hovertipPrepare, try adding css borders to some elements until you find which one you are actually leaving when the tip disappears.


login or register to post comments


IE Add iframe

Submitted by zeno on Tue, 2007-07-24 04:07.

// show the tooltip under the mouse.
// Introduce a delay, so tip appears only if cursor rests on target for more than an instant.
hovertipShowUnderMouse = function(el) {
hovertipHideCancel(el);
if (!hovertipIsVisible(el)) {
el.ht.showing = // keep reference to timer
window.setTimeout(function() {
el.ht.tip.css({
'position':'absolute',
'z-index':'101',
'top': hovertipMouseY + 'px',
'left': hovertipMouseX + 'px'})
.show();

/* Hack: Add iframe */
var ieMat=document.createElement('iframe');
if(document.location.protocol == "https:")
ieMat.src="//0";
else if(window.opera != "undefined")
ieMat.src="";
else
ieMat.src="javascript:false";
ieMat.scrolling="no";
ieMat.frameBorder="0";
ieMat.style.position= 'absolute';
objToolTips = document.getElementById( el.ht.tip.attr('id') );
ieMat.style.width= objToolTips.offsetWidth+"px";
ieMat.style.height= objToolTips.offsetHeight+"px";
ieMat.style.zIndex="-1";
objToolTips.insertBefore(ieMat, objToolTips.childNodes[0]);
objToolTips.style.zIndex="101";
ieMat.style.zIndex="-1";
/* End Hack: Add iframe */

}, el.ht.config.showDelay);
}
};


login or register to post comments


Mouse trailer with hover tip

Submitted by jive on Mon, 2007-07-30 08:21.

Wow. So far the best implemented jquery tool tip script I have found so far. Would be perfect if you added mouse trailing to it, like this jquery tool tip:

http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/

However, this tool tip is not implemented as well as yours...

Any chance that you can add it?


login or register to post comments


I'm confident this could be

Submitted by dave on Wed, 2007-08-01 22:00.

I'm confident this could be added. If anyone comes up with a patch I'd be happy to post it here. It might even be a one-liner. But I'm not interested in working on it myself, because I don't like when the helptip follows the pointer.

I feel the text that pops up should contain useful stuff like links and even nested helptips (as shown in my example above). And you should be able to copy and paste the text in the helptip. If the text keeps moving out from under the mouse you can't do any of that.

I respect your preference to have the text move, but don't have time to work on it myself.


login or register to post comments


XHTML Validation Concern

Submitted by zeno on Fri, 2007-09-14 08:33.

You have to custom the DTD to get the hovertip & clicktip attributes defined. Refer to these two articles:

http://www.alistapart.com/articles/customdtd/

http://www.quirksmode.org/bugreports/archives/2005/02/custom_dtds_int_1.html

<?php header ("Content-type: application/xhtml+xml; charset=utf-8"); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"

[

<!ATTLIST span hovertip CDATA #IMPLIED>
<!ATTLIST span clicktip CDATA #IMPLIED>

]>

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

<head>

<title>Tooltips Demo</title>

<meta http-equiv="Content-Type" content="application/xhtml+xml;charset=utf-8" />

<style type="text/css" media="all">@import "hovertip.css";</style>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript" src="hovertips.js"></script>

<script type="text/javascript">

/* <![CDATA[ */

// initialize tooltips in a seperate thread

$(document).ready(function() {

window.setTimeout(hovertipInit, 1);

});

/* ]]> */

</script>

</head>

<body>

<div>This is an example of a <span hovertip='htdef'>hover tip demo</span> <span class="clicktip_target" clicktip="ctdef">click tips demo</span></div>

<div style='display:none'><div class='hovertip' id="htdef"><h1>What's a hovertip?</h1>A hovertip is a kind of "tooltip" that appears when the mouse rests above something.</div></div>

<div class="clicktip" id="ctdef"><h1>What's a clicktip?</h1> <p>A clicktip is also a tooltip. But unlike a <span hovertip='htdef'>hovertip</span>, the user must press the mouse button to see one.

</p>

</div>

</body>

</html>

login or register to post comments


Viewport Overflow issue

Submitted by deadzoro on Sun, 2007-09-16 10:02.

I really like the behaviors of your tooltip system. The only thing I am looking to fix is the tooltip to appear over the mouse when the link is at the bottom of the page, which cause the page to extend over to desired height. I am sure that this is a quick fix, but I can't figure out how implement it.

Often, sleep gives more answers than forums


login or register to post comments


hovertips

Submitted by debebe on Mon, 2008-02-11 16:23.

Hovertips continue to show under elements with z-index 20.
I changed hovertipShowUnderMouse function, added
'z-index': 60
after 'left': hovertipMouseX + 'px',

limousines


login or register to post comments


Thank you!

Submitted by siliconmeadow@d... on Thu, 2008-05-01 11:05.

The Drupal module works a treat!


login or register to post comments


'tweak' positioning the hovertip relative to mouse

Submitted by Robert Lore on Tue, 2008-05-06 04:21.

Hi there,

I noticed that the hovertip is positioned so that its top left corner is under the mouse when clicked. If the page boundary is close by, or for some other reason you want to put in an offset (or say tl, bl, tr, br corners) you cannot. I tried to change the hovertip js code shown here ('top': hovertipMouseY + 'px' +offset) but it failed. I am quite new to js.

How can you alter the offset for this ?

Regards,
Robert (in OZ)

211 // show the tooltip under the mouse.
212 // Introduce a delay, so tip appears only if cursor rests on target for more than an instant.
213 hovertipShowUnderMouse = function(el) {
214 hovertipHideCancel(el);
215 if (!hovertipIsVisible(el)) {
216 el.ht.showing = // keep reference to timer
217 window.setTimeout(function() {
218 el.ht.tip.css({
219 'position':'absolute',
220 'top': hovertipMouseY + 'px',
221 'left': hovertipMouseX + 'px' })
222 .show();
223 }, el.ht.config.showDelay);
224 }
225 };


login or register to post comments


A couple things about this.

Submitted by dave on Thu, 2008-05-15 01:50.

A couple things about this. The goal was to control placement via stylesheet. If you look at hovertip.css you'll find margin settings for .hovertip. Try changing these first. It's been a while since I've messed with it, but that gives you some control.

If you need to change the function you listed above, say to position relative to the bottom of the tip, you can do that too. The easy way is to just change 'top' to 'bottom', but if you ever update the file later you might run into trouble. So, you can include your own javascript file with alternate definition of hovertipShowUnderMouse() and hovertipTargetPrepare(). Change the latter to call your replacement for the former. Then, intialize the hovertips with a function similar to hovertipInit(), but pass your replacement function for hovertipTargetPrepare. The code is very modular and you can customize a lot of behavior by defining your own javascript functions, but of course you have to know what you're doing.

I have a goal to one day make the hovertip aware of where they are on the window, and if part of them is cut off they would slide to where they are visible. Either that, or make them draggable. Or both. But it's been a long time since I've had time to devote to any of this. If anyone out there is looking for a project...


login or register to post comments