Zebra_Tooltips, a lightweight tooltips jQuery plugin

Get the latest updates on this jQuery plugin via RSS

Zebra_Tooltips is a lightweight (around 5KB minified, 1.6KB gzipped) tooltip jQuery plugin for creating simple but smart and visually attractive tooltips, featuring nice transitions, and offering a wide range of configuration options. The library detects the edges of the browser window and makes sure that the tooltips always stay in the visible area of the browser window by placing them beneath or above the elements, and shifting them left or right so that the tooltips are always visible.

Besides the default behavior of tooltips showing when user hovers the element, tooltips may also be shown and hidden programmatically using the API. When shown programmaticaly, the tooltips will feature a “close” button and clicking it will be the only way of closing tooltips opened this way. This is very useful for drawing users’ attention to specific areas of a website.

By default, Zebra_Tooltips will use the “title” attribute of the element for the tooltip’s content, but the tooltip’s content can also be specified programmatically. Tooltips’ appearance can be easily customized both through JavaScript and/or CSS. Also, tooltips can be aligned left, center or right, relative to the parent element.

Zebra_Tooltips uses NO IMAGES (everything is handled from CSS), and falls back gracefully for browsers that don’t support all the fancy stuff; also, tooltips can be attached to any element not just anchor tags!

Works in all major browsers (Firefox, Opera, Safari, Chrome, Internet Explorer 6+)

Features

  • lightweight (around 5KB minified, 1.6KB gzipped)
  • features nice transitions
  • detects the edges of the browser window and makes sure that the tooltips always stay in the visible area of the browser window by placing them beneath or above the elements and shifting them left or right so that the tooltips are always visible
  • tooltips may also be shown and hidden using the API
  • appearance can be easily customized both through JavaScript and/or CSS
  • tooltips can be aligned left, center or right relative to the parent element
  • uses NO IMAGES (everything is handled from CSS), and falls back gracefully for browsers that don’t support all the fancy stuff; also, tooltips can be attached to any element not just anchor tags!
  • can be attached to any element not just anchor
  • works in all major browsers (Firefox, Opera, Safari, Chrome, Internet Explorer 6+)

Top

Requirements

Zebra_Tooltips has no dependencies other than jQuery. The recommended jQuery version is 1.7+ (due to the fact that the library makes use of something that the previous versions of jQuery have done in a way that it it now deprecated in WebKit powered browsers)

Top

How to use

First, load the latest version of jQuery either from a local source or from a CDN.

Load the Zebra_Tooltip plugin

<script type="text/javascript" src="path/to/zebra_tooltip.js"></script>

Load the plugin’s CSS file

<link rel="stylesheet" href="path/to/zebra_tooltips.css" type="text/css">

Now, within the DOM-ready event do

$(document).ready(function() {

    // show tooltips for any element that has a class named "tooltips"
    // the content of the tooltip will be taken from the element's "title" attribute
    new $.Zebra_Tooltips($('.tooltips'));

 });

Demos

1. Basic usage

The HTML

<p>Lorem ipsum dolor sit amet consectetuer facilisis lacinia sapien ac et. Quis 
hendrerit neque congue pretium iaculis justo laoreet orci elit <a href="#" 
class="tooltips" title="Zebra_Tooltips is a lightweight (around 5KB minified, 1.6KB 
gzipped) tooltip jQuery plugin for creating simple, but smart and visually attractive 
tooltips, featuring nice transitions and offering a wide range of configuration 
options.">condimentum</a>. Eros natoque Curabitur accumsan eget quis porttitor 
Sed Vestibulum amet sed.</p>

The JavaScript

$(document).ready(function() {
    new $.Zebra_Tooltips($('.tooltips'));
});

The result

Lorem ipsum dolor sit amet consectetuer facilisis lacinia sapien ac et. Quis hendrerit neque congue
pretium iaculis justo laoreet orci elit condimentum. Eros natoque Curabitur accumsan eget quis porttitor Sed Vestibulum amet sed.

2. Custom colors

The HTML

<p>Lorem ipsum dolor sit amet consectetuer facilisis lacinia sapien ac et. Quis 
hendrerit neque congue pretium iaculis justo laoreet orci elit <a href="#" 
class="tooltips" title="Appearance can be easily customized both through JavaScript
and/or CSS. Also, tooltips can be aligned left, center or right relative to the 
parent element.">condimentum</a>. Eros natoque Curabitur accumsan eget quis 
porttitor Sed Vestibulum amet sed.</p>

The JavaScript

$(document).ready(function() {
    new $.Zebra_Tooltips($('.tooltips'), {
        'background_color': '#C40000',
        'color': '#FFF'
    });
});

The result

Lorem ipsum dolor sit amet consectetuer facilisis lacinia sapien ac et. Quis hendrerit neque congue
pretium iaculis justo laoreet orci elit condimentum. Eros natoque Curabitur accumsan eget quis porttitor Sed Vestibulum amet sed.

3. Align tooltips relative to the parent element

The HTML

<p>Lorem ipsum dolor sit amet consectetuer facilisis lacinia sapien ac et. Quis 
hendrerit neque congue pretium iaculis justo laoreet orci elit <a href="#" 
class="tooltips1" title="Hello! I am aligned to the left of the element. Also, my
width is different.">left</a>. Eros natoque Curabitur accumsan eget quis 
porttitor Sed Vestibulum amet sed. Lorem ipsum dolor sit amet consectetuer 
facilisis lacinia sapien ac et. Quis hendrerit neque congue pretium iaculis justo 
laoreet orci elit <a href="#" class="tooltips2" title="Hello! I am aligned to 
the right of the element. Also, my width is different.">right</a>. Eros natoque 
Curabitur accumsan eget quis porttitor Sed Vestibulum amet sed.</p>

The JavaScript

$(document).ready(function() {
    new $.Zebra_Tooltips($('.tooltips1'), {
        'position':     'left',
        'max_width':    300
    });

    new $.Zebra_Tooltips($('.tooltips2'), {
        'position': 'right',
        'max_width':    300
    });
});

The result

Lorem ipsum dolor sit amet consectetuer facilisis lacinia sapien ac et. Quis hendrerit neque congue pretium iaculis justo laoreet orci elit left. Eros natoque Curabitur accumsan eget quis porttitor Sed Vestibulum amet sed. Lorem ipsum dolor sit amet consectetuer facilisis lacinia sapien ac et. Quis hendrerit neque congue pretium iaculis justo laoreet orci elit right. Eros natoque Curabitur accumsan eget quis porttitor Sed Vestibulum amet sed.

4. Show tooltips programmatically

The HTML

<p>Lorem ipsum dolor sit amet consectetuer facilisis lacinia sapien ac et. Quis 
hendrerit neque congue pretium iaculis justo laoreet orci elit <a href="#" 
class="tooltips" title="Zebra_Tooltips makes use of NO IMAGES (everything is 
handled from CSS), and falls back gracefully for browsers that don't support all 
the fancy stuff; also tooltips can be attached to any element not just anchor 
tags!<br><br>Works in all major browsers (Firefox, Opera, Safari, Chrome, Internet 
Explorer 6+)">condimentum</a>. Eros natoque Curabitur accumsan eget quis 
porttitor Sed Vestibulum amet sed.</p>

The JavaScript

$(document).ready(function() {
    var zt = new $.Zebra_Tooltips($('.tooltips'));
    zt.show($('.tooltips'), true); // destroy on close
});

The result

Lorem ipsum dolor sit amet consectetuer facilisis lacinia sapien ac et. Quis hendrerit neque congue
pretium iaculis justo laoreet orci elit condimentum. Eros natoque Curabitur accumsan eget quis porttitor Sed Vestibulum amet sed.

 

Top

Configuration

All parameters are optional.

animation_speed integer

The speed (in milliseconds) of the animation used to show/hide tooltips. 

Default is 250

animation_offset integer

The number of pixels the tooltips should use to “slide” into position. 

Set to 0 for no sliding.

Default is 20.

background_color string

Tooltip’s background color. 

May be a hexadecimal color (like #BADA55) or a supported named color (like “limegreen”).

Default is #000

close_on_click boolean

By default, if the users clicks when over a tooltip, the tooltip will close (if the tooltip was not open using the API, that is). 

Set this property to FALSE to prevent this behaviour.

Default is TRUE

color string

Tooltip’s text color. 

May be a hexadecimal color (like #FFF) or a supported named color (like “white”).

Default is #FFF.

content string

The content of the tooltip. 

Usually, the content of the tooltip is given in the “title” attribute of the DOM element the tooltip is attached to.

Setting this property to FALSE will use the property’s value as the content of all the tooltips rather than values the tooltips’ “title” attribute.

Default is FALSE

hide_delay integer

The delay (in milliseconds) after which to hide the tooltip once the mouse moves away from the trigger element or the tooltip. 

Default is 100.

keep_visible boolean

Should tooltips remain visible also when the mouse cursor is over the tooltips or should the tooltips be visible strictly when the mouse cursor is over the parent elements. 

Default is TRUE.

max_width integer

Maximum width of the tooltip’s content; 

Default is 250

opacity double

The tooltip’s opacity. 

Must be a value between 0 (completely transparent) and 1 (completely opaque)

Default is .85

position string

The tooltip’s position, relative to the trigger element. 

Can be any of the following:

- center
- left
- right

Default is “center”.

prerender boolean

If set to TRUE, tooltips will be created on document load, rather than only when needed. 

Default is FALSE.

show_delay integer

The delay (in milliseconds) after which to show the tooltip once the mouse is over the trigger element. 

Default is 100.

vertical_offset integer

How close (in pixels) should the tip of the tooltip be relative to the parent element. 

Default is 0.

Events

onBeforeHide  

Event fired before a tooltip is hidden. 

The callback function (if any) receives as argument the DOM element the tooltip is attached to.

onHide  

Event fired after a tooltip is hidden. 

The callback function (if any) receives as argument the DOM element the tooltip is attached to.

onBeforeShow  

Event fired before a tooltip is shown. 

The callback function (if any) receives as argument the DOM element the tooltip is attached to.

onShow  

Event fired after a tooltip is shown. 

The callback function (if any) receives as argument the DOM element the tooltip is attached to.

Public methods

show  

Shows the tooltip attached to the element or the elements given as argument. 

When showing a tooltip using this method, the tooltip can only be closed by the user clicking on the “close” icon on the tooltip (which is automatically added when using this method) or by calling the hide() method.

show(element, [destroy = FALSE])

where

element: An element or a collection of elements for which to show the attached tooltips.

destroy: (optional) If set to TRUE, once the user clicks the “close” button, the tooltip will be “muted” and will *not* be shown when the user hovers the parent element with the mouse.

In this case, the tooltip can be shown again only by calling this method.

If set to FALSE, the tooltip will be shown whenever the user hovers the parent element with the mouse, only it will not have the “close” button anymore.

Default is FALSE

var zt = new $.Zebra_Tooltips($('#tooltip'));
zt.show($('#tooltip'), true);
hide  

Hides the tooltip attached to the element or the elements given as argument. 

hide(element, [destroy = FALSE])

where

element: An element or a collection of elements for which to show the attached tooltips.

destroy: (optional) If set to TRUE, once hidden, the tooltip will be “muted” and will *not* be shown when the user hovers the parent element with the mouse.

In this case, the tooltip can be shown again only by calling the show() method.

Default is FALSE

var zt = new $.Zebra_Tooltips($('#tooltip'));
zt.hide($('#tooltip'));

Top 

Download

version 1.1.0
If you find this library to be useful to you, you can support the author by donating a small amount via PayPal:

Zebra_Tooltips is distributed under the LGPL.

In plain English, this means that you have the right to view and to modify the source code of this software, but if you modify and distribute it, you are required to license your copy under a LGPL-compatible license, and to make the entire source code of your derivation available to anybody you distribute the software to.

You also have the right to use this software together with software thas has different licensing terms (including, but not limited to, commercial and closed-source software), and distribute the combined software, as long as state that your software contains portions licensed under the LGPL license, and provide information about where the LGPL licensed software can be downloaded.

If you distribute copies of this software you may not change the copyright or license of this software.


You may also like:

Top

Changelog

Click on a version to expand/collapse information.

version 1.1.0 (April 28, 2013)
  • a new property was added: “vertical_offset” which sets how close (in pixels) should the tip of the tooltip’s arrow be relative to the parent element; thanks Jason Lewis;
  • tooltip’s width can now be set when initializing the plugin;
  • fixed a bug where the tooltip was not having an animation the first time it was shown but only on subsequent appearances;
  • fixed a bug with the arrow’s container element, even though invisible, was larger than needed;
  • fixed a bug which broke the tooltip’s animation if, during it’s lifetime, a tooltip was shown above/below an element and then, because of scrolling or resizing, the tooltip had to be shown below/above the element;
  • fixed some positioning bugs when resizing the window or having scrollbars;
  • some optimizations and changes in the stylesheet file;
  • the project is now also available on GitHub
version 1.0.1 (May 11, 2012)
  • fixed a bug where in Internet Explorer 9 the arrow was sometimes not visible; thanks to Manfred and tolpi
version 1.0 (January 02, 2012)
  • initial release

Top

44 responses to “Zebra_Tooltips, a lightweight tooltips jQuery plugin”

Follow the comments via RSS
  • Sean, 2013-05-09, 18:36

    Possible to do a “seperator” in this Tooltip. Example

    title=’Settings|Change your Setting’

    So my tooltip would have a Setting as Header, then Change your Setting as body of that tooltip?

    Reply
    • Stefan Gabos, 2013-05-10, 06:36

      try something like this

      <a 
      href="#" 
      class="tooltips" 
      title="<strong>Settings</strong><br>Change your settings">
      Settings</a>
    • Sean, 2013-05-10, 07:57

      Close but not what I’m looking for, Currently I have this:

      <span style='float:right;' class='ui-icon ui-icon-wrench ToTip' id='ThemeSettingO' title="Theme SettingChange Themes Settings!”>

      then in Stylesheet:
      .TiTip {width:150px;border:1px solid #111111 !important;}
      .HeTip {width:150px;height:16px;max-height:16px;padding:2px;text-align:center;font-weight:bold;-moz-border-radius-topleft:5px;-webkit-border-top-left-radius:5px;-moz-border-radius-topright:5px;-webkit-border-top-right-radius:5px;filter:alpha(opacity=100);opacity:100;}
      .BoTip {width:150px;padding:4px;-moz-border-radius-bottomleft:5px;-webkit-border-bottom-left-radius:5px;-moz-border-radius-bottomright:5px;-webkit-border-bottom-right-radius:5px;filter:alpha(opacity=100);opacity:100;}

      It would produce something like what you saw in GitHub (tooltip sample in bug report)

  • Sean, 2013-05-09, 21:26

    How/where can I change the color of the arrow?

    Reply
    • Stefan Gabos, 2013-05-10, 06:41

      The color of the tooltip (including the arrow) can be changed via the “background-color” property; for setting *only* the arrow’s color, you’ll have to hack the source code and change the color at line 526 in zebra_tooltips.src.js

  • Sean, 2013-05-10, 07:59

    Ack! It removed my html codes lol..

    <span style='float:right;' class='ui-icon ui-icon-wrench ToTip' id='ThemeSettingO' title="Theme SettingChange Themes Settings!">
    
    Reply
  • Sean, 2013-05-18, 18:55

    Have an issue with tooltip. When I create an AJAX and pulls data from an external file and the tag has “title” in it, after the result is outputted, the “title” would not display tooltip properly, it would act like an “Alt=” instead of title. Any workaround for that?

    Reply
    • Sean, 2013-05-18, 19:39

      Found a bit sloppy workaround, but it works, so never mind about that :)

Leave a Reply

Your email address will not be published
You can use <strong>, <em>, <a>, <img>, <code>
Characters are not case-sensitive