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:

  • I've noticed that only a few of the styles work properly with aligning X in the center. For example, tip-twitter and tip-yellowsimple will put the arrow in the middle of the poshytip box, but tip-darkgray and tip-yellow always put it at the end regardless of alignment. Is this just a constraint of using a more complicated style?

    #60 by: Jason on June 15, 2011 at 03:40
  • You can ignore/delete my last comment. JQuery's proxy() method was not introduced until Version 1.4

    #59 by: SteveM on June 8, 2011 at 19:07
  • Have you encountered this error before:

    Uncaught TypeError: Object function (E,F){return new o.fn.init(E,F)} has no method 'proxy'

    Our site is still using jQuery JavaScript Library v1.3.2

    #58 by: SteveM on June 8, 2011 at 19:04
  • ' tip-yellow' don't use background image ,Why not use ie browser?

    #57 by: zhang on June 7, 2011 at 04:36
  • admin

    @zhang

    I am not completely sure but if by "gradual" you mean tiled, you will need to set the background image to the inner DIV instead (i.e. .tip-yellow .tip-inner) and remove the background image declaration for .tip-yellow - there is a comment about it in the CSS file.

    #56 by: Vasil Dinkov on June 3, 2011 at 22:12
  • className : tip-yellow's Images background can be gradual?

    #55 by: zhang on June 3, 2011 at 10:05
  • @Shahram Javed

    I read your comment on how poshytip didn't work in a jQuery UI dialog. If you happen to read this or for future googlers:

    The jQuery UI dialog has a z-index of 1001. You need to provide a larger z-index for the poshytip for it to display on top of the dialog and not underneath it. The most simple way to do that is to add the following CSS-snippet in your code somewhere:

    .tip-yellow {
    z-index: 1050;
    }

    This solves the problem.

    BTW,
    Thanks for the great poshytip plugin!

    #54 by: Anders Hansson on May 27, 2011 at 11:56
  • admin

    @Shahram

    Have you tried tweaking the default z-index for the tooltips (in the CSS file you use):

    .tip-yellow {
          z-index:1000;
          ...

    Try using some larger number.

    #53 by: Vasil Dinkov on May 17, 2011 at 16:35
  • 幸苦你们了!

    #52 by: 黄波 on May 16, 2011 at 17:55
  • Hi vasil
    i am using poshytip on Jquery UI dialoag popup, but tooltip is not coming properly, it shows me tooltip in backgroud not above the dialog box, can u suggest me any solution.

    #51 by: Shahram Javed on May 16, 2011 at 17:48
  • great! great!

    #50 by: jingwei on May 15, 2011 at 17:48
  • admin

    @Veselin

    Hah, would be great! :) Cheers!

    #49 by: Vasil Dinkov on May 11, 2011 at 00:04
  • Thanks @Vasko :)

    Some day I can buy you a bear :) (I also live in Plovdiv)

    #48 by: Veselin on May 10, 2011 at 17:48
  • admin

    @Veselin

    Yep, this is a known jQuery 1.6 bug that's already fixed (the fix will be included in 1.6.1):

    http://bugs.jquery.com/ticket/9074

    Nonetheless, I will also commit a workaround for the bug in 1.6 with the next changeset...

    #47 by: Vasil Dinkov on May 10, 2011 at 17:40
  • I also upgraded to jQuery 1.6 and don't have the @Dan Brooke's error, but the slide + fade animation doesn't work properly.

    #46 by: Veselin on May 10, 2011 at 16:42
  • admin

    @Dan Brooke

    I was just reported the other day about this issue with jQuery 1.6. I will check it these days (I just need to find some free time, hopefully, by the end of the week) and commit a fix to the GitHub repository. The fix will also be included in v1.1 which is coming very soon but feel free to check the GitHub repository these days if you'd like to get the fix ASAP.

    Cheers!

    #45 by: Vasil Dinkov on May 10, 2011 at 16:14
  • I am just upgrading my app to use jQuery 1.6 and seem to be having a problem with PoshyTip, the error is "Uncaught TypeError: Cannot call method 'data' of undefined". Any ideas? Thanks.

    #44 by: Dan Brooke on May 10, 2011 at 12:54
  • thanks a lot

    #43 by: sub on April 13, 2011 at 06:01
  • @Progys, I was having the same problem... I changed from id="" to class="" and all worked fine.
    $('.demo-green').poshytip({
    vs.
    $(#demo-green').poshytip({

    and
    <a class="demo-green"
    vs.
    <a id="demo-green"

    #42 by: stu gotz on April 2, 2011 at 02:11
  • Hi,
    How can I use the tooltips for many link, I try with a DIV like this exemple 'Loading Flickr Feeds' ?
    I wont going to to a code for each item ? I Have 12 on the same page. (of course without the other lib that I wanted to libellate with)
    Actually when I use that code, the first link has the effect and the other the 'original' effect.
    [a]id="demo-basic" title="Hey, there! txt#1" href="#">1st link[/a]
    [a]id="demo-basic" title="Hey, there! txt#2" href="#">2nd link[/a]
    ...

    #41 by: Progys on March 29, 2011 at 03:54

Post a Comment: