Poshy Tip jQuery Plugin Demo Page
254 | 255 |Usage Examples
256 | 257 |The default browser tooltip that displays the value of the title attribute is replaced with a "poshier" version:
$('#demo-basic').poshytip();
263 | Styles (Classes)
266 | 267 |Using different tooltip classes is easy. Here are some examples that are included in the download package (in the "src" folder).
268 | 269 | 270 | 271 |$('#demo-tip-yellow').poshytip();
273 | $('#demo-tip-violet').poshytip({
279 | className: 'tip-violet',
280 | bgImageFrameSize: 9
281 | });
282 | $('#demo-tip-darkgray').poshytip({
288 | className: 'tip-darkgray',
289 | bgImageFrameSize: 11,
290 | offsetX: -25
291 | });
292 | $('#demo-tip-skyblue').poshytip({
298 | className: 'tip-skyblue',
299 | bgImageFrameSize: 9,
300 | offsetX: 0,
301 | offsetY: 20
302 | });
303 | .tip-yellowsimple (no background-image used for the tooltip body)
307 |$('#demo-tip-yellowsimple').poshytip({
309 | className: 'tip-yellowsimple',
310 | showTimeout: 1,
311 | alignTo: 'target',
312 | alignX: 'center',
313 | offsetY: 5,
314 | allowTipHover: false
315 | });
316 | .tip-twitter (ala Twitter)
320 |$('#demo-tip-twitter').poshytip({
322 | className: 'tip-twitter',
323 | showTimeout: 1,
324 | alignTo: 'target',
325 | alignX: 'center',
326 | offsetY: 5,
327 | allowTipHover: false,
328 | fade: false,
329 | slide: false
330 | });
331 | $('#demo-tip-green').poshytip({
337 | className: 'tip-green',
338 | offsetX: -7,
339 | offsetY: 16,
340 | allowTipHover: false
341 | });
342 | Form Tooltips (with varying positioning)
345 | 346 |Adding form input field tooltips is simple. You just have to make sure they are triggered on focus/blur (i.e. showOn: 'focus') and positioned relatively to the target element (i.e. alignTo: 'target'). The script also updates the position of such tooltips if the window is resized (e.g. show some of the tips below and resize your browser window for a demo).
350 |
351 |
352 |
$('#demo-form-name').poshytip({
355 | className: 'tip-yellowsimple',
356 | showOn: 'focus',
357 | alignTo: 'target',
358 | alignX: 'right',
359 | alignY: 'center',
360 | offsetX: 5,
361 | showTimeout: 100
362 | });
363 |
367 |
368 |
369 |
$('#demo-form-email').poshytip({
372 | className: 'tip-yellowsimple',
373 | showOn: 'focus',
374 | alignTo: 'target',
375 | alignX: 'left',
376 | alignY: 'center',
377 | offsetX: 5,
378 | showTimeout: 100
379 | });
380 |
384 |
385 |
386 |
$('#demo-form-site').poshytip({
389 | className: 'tip-yellowsimple',
390 | showOn: 'focus',
391 | alignTo: 'target',
392 | alignX: 'inner-left',
393 | offsetX: 0,
394 | offsetY: 5,
395 | showTimeout: 100
396 | });
397 |
401 |
402 |
403 |
$('#demo-form-subject').poshytip({
406 | className: 'tip-yellowsimple',
407 | showOn: 'focus',
408 | alignTo: 'target',
409 | alignX: 'center',
410 | alignY: 'bottom',
411 | offsetX: 0,
412 | offsetY: 5,
413 | showTimeout: 100
414 | });
415 | Asynchronous Loading of the Content
418 | 419 |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. The script also recalculates and updates the position of the tooltip when its content is updated.
420 | 421 |Simple Example
422 | 423 | 424 | 425 |$('#demo-async-timeout').poshytip({
427 | content: function(updateCallback) {
428 | window.setTimeout(function() {
429 | updateCallback('Tooltip content updated!');
430 | }, 1000);
431 | return 'Loading...';
432 | }
433 | });
434 | Loading Flickr Feeds
437 | 438 |A more complicated example of loading some Flickr images by tags:
439 | 440 | 441 |flowers, closeup, sunset, architecture, Plovdiv, old, town, Nesebar, depeche
442 | 443 | 444 |var flickrFeedsCache = {};
446 |
447 | $('#demo-async-flickr > a').poshytip({
448 | className: 'tip-darkgray',
449 | bgImageFrameSize: 11,
450 | alignY: 'bottom',
451 | content: function(updateCallback) {
452 | var rel = $(this).attr('rel');
453 | if (flickrFeedsCache[rel] && flickrFeedsCache[rel].container)
454 | return flickrFeedsCache[rel].container;
455 | if (!flickrFeedsCache[rel]) {
456 | flickrFeedsCache[rel] = { container: null };
457 | var tagsComma = rel.substring(4).replace('-', ',');
458 | $.getJSON('http://api.flickr.com/services/feeds/photos_public.gne?tags=' + tagsComma + '&tagmode=all&format=json&jsoncallback=?',
459 | function(data) {
460 | var container = $('<div/>').addClass('flickr-thumbs');
461 | $.each(data.items, function(i, item) {
462 | $('<a/>')
463 | .attr('href', item.link)
464 | .append($('<img/>').attr('src', item.media.m))
465 | .appendTo(container)
466 | .data('tip', '<strong>' + (item.title || '(no title)') + '</strong><br />by: ' + item.author.match(/\((.*)\)/)[1]);
467 | if (i == 4)
468 | return false;
469 | });
470 | // add tips for the images inside the main tip
471 | container.find('a').poshytip({
472 | content: function(){return $(this).data('tip');},
473 | className: 'tip-yellowsimple',
474 | showTimeout: 100,
475 | alignTo: 'target',
476 | alignX: 'center',
477 | alignY: 'bottom',
478 | offsetY: 5,
479 | allowTipHover: false,
480 | hideAniDuration: 0
481 | });
482 | // store the content in the cache
483 | // and call updateCallback() to update the content in the main tooltip
484 | updateCallback(flickrFeedsCache[rel].container = container);
485 | }
486 | );
487 | }
488 | return 'Loading images...';
489 | }
490 | });
491 | Following the Mouse Cursor
494 | 495 |If using the followCursor: true option, it's better to make sure the the slide animation effect is disabled (i.e. slide: false) so that it doesn't conflict with the code that moves the tooltip with the cursor.
Hover for a tooltip that follows the cursor
499 |$('#demo-follow-cursor').poshytip({
501 | followCursor: true,
502 | slide: false
503 | });
504 | API Example - Triggering the Tooltip Manually
507 | 508 |If you like, you can add a tooltip to some element(s) and configure it to not be triggered automatically on hover or focus/blur by using the showOn: 'none' option. You can then control the tooltip manually via the available methods.
This link has a tooltip that is not triggered automatically
512 |513 |
$('#demo-manual-trigger').poshytip({
515 | content: 'Hey, there! This is a tooltip.',
516 | showOn: 'none',
517 | alignTo: 'target',
518 | alignX: 'inner-left',
519 | offsetX: 0,
520 | offsetY: 5
521 | });
522 | $('#button-show').click(function() { $('#demo-manual-trigger').poshytip('show'); });
523 | $('#button-show-delayed').click(function() { $('#demo-manual-trigger').poshytip('showDelayed', 2000); });
524 | $('#button-hide').click(function() { $('#demo-manual-trigger').poshytip('hide'); });
525 | $('#button-hide-delayed').click(function() { $('#demo-manual-trigger').poshytip('hideDelayed', 2000); });
526 | $('#button-update').click(function() { $('#demo-manual-trigger').poshytip('update', 'I am a new content :)'); });
527 | $('#button-disable').click(function() { $('#demo-manual-trigger').poshytip('disable'); });
528 | $('#button-enable').click(function() { $('#demo-manual-trigger').poshytip('enable'); });
529 | $('#button-destroy').click(function() { $('#demo-manual-trigger').poshytip('destroy'); });
530 | Using Live Events
533 | 534 |You can set the liveEvents: true option to use live events. Note that the API methods (except 'destroy') won't work reliably in such case. They will only work for the elements for which the tooltip has been initialized (i.e. shown at least once). Live events are supported in jQuery 1.4.2+.
$('#demo-live-events > a').poshytip({
541 | liveEvents: true
542 | });
543 | $('#button-live-events').click(function() {
544 | $('#demo-live-events').append(', <a title="Hey, there! This is a tooltip." href="#">Hover for a tooltip</a>');
545 | });
546 | Options
549 | 550 | 620 | 621 |Methods
622 | 623 | 651 | 652 |Notes
653 | 654 |-
655 |
- Requires jQuery 1.4+ 656 |
- Works in IE6+, FF 2+, Opera 9+, Safari 3+, Chrome 657 |
- In IE6 min/max-width are supported (only px values) for the tooltip container DIV so you can use them in your CSS without worrying for IE6 (if you still care about it) 658 |
- When a background-image is set for the tooltip container DIV, the script will neglect the background-color/padding/border declarations set for it and will use the background image to create a scalable frame around the tooltip inner DIV (for an explanation how this works, please take a look at the Poshy Tip Page) 659 |
- In IE6 PNG background images are not supported (only GIF). If a PNG is set as a background-image for the tooltip container, in IE6 the script will fallback and use the background-color/padding/border declarations instead. 660 |
License
663 | 664 |Like jQuery, Poshy Tip is dual licensed under the MIT and GPL licenses.
665 | 666 |Download
667 | 668 |Download link: http://vadikom.com/files/?file=poshytip/poshytip-1.2.zip
669 | 670 |Git
671 | 672 |The Poshy Tip source code is also available at GitHub:
673 |git clone git://github.com/vadikom/poshytip.git675 |
Support
678 | 679 |Post your questions/suggestions in the support forums.
680 | 681 |Donate
682 | 683 |If you appreciate this script, you can support me by donating a small amount through PayPal or just by spreading the word about it. Your support is highly appreciated!
684 |