Poshy Tip - jQuery Plugin for Stylish Tooltips

I almost hear you asking - why another jQuery tooltip plugin? Well, I actually never planned creating this plugin until I reached the final stages of designing this website and decided to add some pretty tooltips. So I started looking for a tooltip plugin that allows easily creating stylish tooltips and also includes the most useful features for such a script. However, I wasn't pleased with the results I found so I ended up writing a completely new plugin and am now making it available for all.

Demos

You might be eager to take a look at some examples so here is the demo page right away. And below you will find a short introduction.

Notable Features

OK, so apart from the awful name, is there anything interesting about this tooltip plugin?

A Single Background Image for Scalable Tooltips

Suppose you need to code a scalable tooltip that looks like this (i.e. a tooltip with auto width/height based on the content inside it):

A figure showing a tooltip mockup that should be used to create a scalable tooltip on the page

The Usual Approach

To achieve this with most similar plugins out there you would need to slice the image into multiple separate images - for the corners of the box, for the sides, etc.:

A figure showing how you would normally need to slice the mockup into 9 images in order to code a scalable tooltip

The Poshy Tip Approach

But since the tooltips only work when JavaScript is enabled anyway, why not apply some JS magic which would make our life easier and save our server some additional requests? This is exactly what Poshy Tip was designed to do. With this plugin, you can create a scalable tooltip by just using a single background image for the tooltip body:

With Poshy Tip you need just 2 images - one for the tooltip body + 1 for the arrow

You need to create one big image for the tooltip body - e.g. something like 1024x768 pixels (which should be enough for anything you may want to display inside a tooltip in the browser viewport). You then have to set it as a background image for the tooltip container DIV in the most trivial way:

.tip-yellow {
	...
	background-image: url(tip-yellow.png);
}

Poshy Tip detects when a background image has been set for the tooltip container DIV and creates a scalable frame from it that wraps the inner contents of the tip. Finally, you just need to specify what should be the size of the background image frame around the inner content by setting the following option:

bgImageFrameSize: 10 // pixels

And the result:

A figure showing the scalable frame created from the background image that wraps the inner DIV

You can, of course, tweak the margin/padding of the inner DIV if needed.

Advanced Positioning Options

With Poshy Tip you can position the tips relative to the mouse cursor or to the target element and align them in every possible way horizontally and vertically (note the alignTo, alignX and alignY options). In addition the script makes sure the tips are always displayed in the browser viewport and also automatically positions the arrow (if available) on the appropriate side of the tooltip body.

Asynchronous Loading of the Tooltip Content

Poshy Tip supports using a function for returning the tooltip content and the script also passes an update callback function as an argument to this function. By using this callback, you can easily update asynchronously the content of the tooltip after it has been displayed. You can see a quick example on the demo page.

Documentation

You can find usage examples and a list of the options and methods available on the demo page.

License

Like jQuery, Poshy Tip is dual licensed under the MIT and GPL licenses.

Git

The Poshy Tip source code is also available at GitHub:

git clone git://github.com/vadikom/poshytip.git

Liked this post?

Don't wait & subscribe to RSS or email updates now.
Quick Tip: Sharing is also easy with the share menu below. :)

Comments:

  • The demos are great! Hope to have a chance to use this in the future. Right now just lookin' around to see what jQuery has to offer and it looks like phoshy tip will go into my tool box. Thank you... TTFN

    #60 by: Andrea on December 4, 2010 at 01:20
  • Maximum kudos on the fantastic bubble/tooltip plugin!

    However, there is a bug in IE6, when one of the elements is float:right. In this case, the bubble is taking on the full width of the browser, when it should only be about 100 pixels wide (a little wider than the buttons that are there). See here: http://img197.imageshack.us/img197/1556/capturerth.png.

    In all other browsers (that I care about), Chrome, FF, IE 7/8/9, Opera, Safari it works fine.

    I can probably take care of this by floating the element inside another fixed-width div, which is fine by me.

    Many thanks for your fine work!

    This is my code for creating the tip.

    $('#Print').poshytip({
    content: $('#PrintContent'),
    className: 'tip-yellowsimple',
    alignTo: 'target',
    alignX: 'center',
    alignY: 'bottom',
    offsetX: 0,
    offsetY: 5,
    bgImageFrameSize: 10,
    showOn: 'none'
    })

    The html:

    <div id="PrintContent">
    <div class="CloseButton">
    </div>
    <div style="clear: both; float: none;">
    </div>
    <a id="8.5x11" href="#" target="_blank">8.5x11</a>
    <a id="3x5" href="#" target="_blank">3x5 Card</a>
    <a id="4x6" href="#" target="_blank">4x6 Card</a>
    </div>

    The css:

    #PrintContent a
    {
    display: block;
    background-image: url(/images/Buttons/BlueButton.png);
    background-repeat: no-repeat;
    background-position: top left;
    background-color: transparent;
    font-family: Verdana !important;
    font-size: 8pt;
    color: White;
    margin: 0px 0px 10px 0px;
    padding: 0px;
    width: 74px;
    height: 20px;
    line-height: 20px;
    text-decoration: none;
    text-align: center;
    }
    #PrintContent a:hover
    {
    background-image: url(/images/Buttons/BlueButton_active.png);
    color: #4b4b4b;
    }
    .CloseButton
    {
    background-image: url(/images/Buttons/CloseButton.png);
    background-repeat: no-repeat;
    background-position: top left;
    background-color: transparent;
    margin: 0px 0px 6px 0px;
    cursor: pointer;
    height: 12px;
    width: 12px;
    float: right; /* <== the offending css code */
    }

    #59 by: andrew on December 3, 2010 at 01:44
  • Reaction a little slow, and takes a bit of high CPU

    #58 by: carlos on December 2, 2010 at 04:35
  • Great ! thanks!

    #57 by: liuweifeng on December 1, 2010 at 16:02
  • Hello,

    When I am using this (great btw) plugin with slide: false and with content update callback, then after the content is updated, the tip is redrawn with slide: true.

    Would appreciate a quick fix :)

    #56 by: Dennis on October 13, 2010 at 12:47
  • Great plugin, the best in tooltips out there! :D

    But I have a doubt, how can I put a single image inside the tooptip. I see your Flickr example but I just put one image, and I do not know much about JavaScript/jQuery.

    Can you help me?

    Thank you!

    #55 by: Edmundo Junior on October 4, 2010 at 17:29
  • admin

    @Carpii Nope, unfortunately, it requires 1.4+ and always has. I am not sure where you have seen that it recommends 1.3 :-\

    #54 by: Vasil Dinkov on September 4, 2010 at 14:27
  • Hi,
    PoshyTip looks great, but Ive had some difficulty getting it to work.
    Error = $.proxy is not defined in jQuery.

    I notice your demos now seem to use jQuery 1.4, but the plugin recommends 1.3.2 (which is what I use since Ive had problems with 1.4).

    Have the requirements for poshyTip changed recently?

    Thanks

    #53 by: Carpii on September 4, 2010 at 05:46
  • admin

    @dirk Instead of min-width/max-width, you should just use width in the CSS. That's all.

    #52 by: Vasil Dinkov on August 26, 2010 at 16:18
  • Right now using and I love it !
    Cannot find anything in your documentation about combination of image and tekst, html, and fixed width, etc.
    Will need to find out!
    The fixed width is my important wish, so I will dive into your style sheet..

    #51 by: dirk on August 25, 2010 at 22:06