clueTip : A jQuery Plugin

Note: This version of the clueTip plugin is no longer being supported. Please visit the clueTip project page for the most recent version. Also, the demo page has been moved.

This is a demo page for the new clueTip — a jQuery-based, AJAX-powered tooltip developed by Karl Swedberg. The clueTip plug-in was inspired by Cody Lindley's jTip script. Many feature ideas were provided by Shelane Enos. Glen Lipka and Jörn Zaefferer provided expert advice. Jonathan Chaffer helped a lot, but eschewed the co-author designation out of sheer modesty.

Features

The clueTip plug-in allows you to easily set a link to show a "tooltip" of sorts when the user's mouse hovers over the link. If the link includes a title attribute, its text becomes the heading of the clueTip. The contents of the clueTip can come from one of these sources:

  1. a separate file, via AJAX
  2. an element on the same page, typically hidden
  3. the title attribute, parsed by a user-defined delimiter (if the "splitTitle" option is set). The text before the first delimiter becomes the clueTip title, and the rest of the text parts are placed in <div class="split-body"></div> elements and appended to the clueTip body

The clueTip offers smart positioning:

The clueTip takes advantage of Brian Cherne's fantastic hoverIntent plugin if it's available. (Just include it in a <script> tag if you want the clueTip to use it.)

The clueTip comes with the following options:

Setup

To use the plug-in, you'll need to include 4 JavaScript files in your web page's <head>, like so:

    <script src="scripts/jquery.js" type="text/javascript"></script>
    <script src="scripts/jquery.dimensions.js" type="text/javascript"></script>
    <script src="scripts/jquery.cluetip.js" type="text/javascript"></script>
    <script src="scripts/your-custom-file.js" type="text/javascript"></script>

As you can see, the clueTip depends on jquery.js and jquery.dimensions.js to function properly.

If you would like to use clueTip in conjunction with the hoverIntent plugin, you will need to reference that plugin as well.

Examples

Here are some examples of how you can add a clueTip to your page:

  1. basic, no title: $('a.basic').cluetip();. This is the simplest example there is: <a class="basic" href="ajax.htm" rel="ajax.htm">
  2. custom width and title: $('a.custom-width').cluetip({width: '200px'}); This tip has a custom width and title: <a class="custom-width" href="ajax3.htm" title="Fancy Title!" rel="ajax3.htm">
  3. non-link element, custom attribute: $('h4').cluetip({attribute: 'id', hoverClass: 'highlight'});

    <h4 id="ajax3.htm">Hover over me</h4>

  4. sticky: $('#sticky').cluetip({sticky: true}); This is a sticky clueTip: <a id="sticky" href="ajax6.htm" rel="ajax6.htm">. It won't close until you close it. Or until you hover over another clue-tipped link.
  5. local: $('a.load-local').cluetip({local:true}); This one uses local content from a hidden div element: <a class="load-local" href="#loadme" rel="#loadme">
  6. sticky, truncated clueTip with custom hover class, close position, and close text (it also has a title):
    $('#examples a:eq(4)').cluetip({
      hoverClass: 'highlight',
      sticky: true,
      closePosition: 'bottom',
      closeText: '<img src="styles/cross.png" alt="" />'
      truncate: 60
    });
    If you click this link — <a href="http://www.learningjquery.com" title="about this link:" rel="ajax6.htm"> — you'll be directed to learningjquery.com
  7. new! click to activate: $('#clickme').cluetip({activation: 'click'}); This one won't show the clueTip unless you click it <a href="ajax5.htm" rel="ajax5.htm" title="active ingredients">

Default Styles

You can style your clueTips any way you want. Here are the default styles:

#cluetip {
  z-index: 1001;
}
#cluetip-outer {
  position: relative;
  margin: 0;
  background: #d9d9c2;
}
h3#cluetip-title {
  margin: 0 0 5px;
  padding: 8px 10px 4px;
  font-size: 1.1em;
  font-weight: normal;
  background-color: #87876a;
  color: #fff;
}
#cluetip-inner {
  padding: 10px;
}
span#cluetip-close { 
  text-align: right;
  margin: 0 5px 5px;
  color: #900;
}
#cluetip-close img {
  border: 0;
}

this is the local content to load when the 'local' parameter is set to true. Currently it only works with an id selector.

Known Issues and To Do

Here is a list of bugs and features I've been working on:

Downloads

ClueTip

Dependencies