Poshy Tip jQuery Plugin 演示页面
用法例子
$('#demo-basic').poshytip();
Styles (Classes)
$('#demo-tip-yellow').poshytip();
$('#demo-tip-violet').poshytip({ className: 'tip-violet', bgImageFrameSize: 9 });
$('#demo-tip-darkgray').poshytip({ className: 'tip-darkgray', bgImageFrameSize: 11, offsetX: -25 });
$('#demo-tip-skyblue').poshytip({ className: 'tip-skyblue', bgImageFrameSize: 9, offsetX: 0, offsetY: 20 });
.tip-yellowsimple (no background-image used for the tooltip body)
$('#demo-tip-yellowsimple').poshytip({ className: 'tip-yellowsimple', showTimeout: 1, alignTo: 'target', alignX: 'center', offsetY: 5, allowTipHover: false });
.tip-twitter (ala Twitter)
$('#demo-tip-twitter').poshytip({ className: 'tip-twitter', showTimeout: 1, alignTo: 'target', alignX: 'center', offsetY: 5, allowTipHover: false, fade: false, slide: false });
$('#demo-tip-green').poshytip({ className: 'tip-green', offsetX: -7, offsetY: 16, allowTipHover: false });
Form Tooltips (with varying positioning)
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).
$('#demo-form-name').poshytip({ className: 'tip-yellowsimple', showOn: 'focus', alignTo: 'target', alignX: 'right', alignY: 'center', offsetX: 5 });
$('#demo-form-email').poshytip({ className: 'tip-yellowsimple', showOn: 'focus', alignTo: 'target', alignX: 'left', alignY: 'center', offsetX: 5 });
$('#demo-form-site').poshytip({ className: 'tip-yellowsimple', showOn: 'focus', alignTo: 'target', alignX: 'inner-left', offsetX: 0, offsetY: 5 });
$('#demo-form-subject').poshytip({ className: 'tip-yellowsimple', showOn: 'focus', alignTo: 'target', alignX: 'center', alignY: 'bottom', offsetX: 0, offsetY: 5 });
Asynchronous Loading of the 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. The script also recalculates and updates the position of the tooltip when its content is updated.
Simple Example
$('#demo-async-timeout').poshytip({ content: function(updateCallback) { window.setTimeout(function() { updateCallback('Tooltip content updated!'); }, 1000); return 'Loading...'; } });
Loading Flickr Feeds
A more complicated example of loading some Flickr images by tags:
flowers, closeup, sunset, architecture, Plovdiv, old, town, Nesebar, depeche
var flickrFeedsCache = {}; $('#demo-async-flickr > a').poshytip({ className: 'tip-darkgray', bgImageFrameSize: 11, alignY: 'bottom', content: function(updateCallback) { var rel = $(this).attr('rel'); if (flickrFeedsCache[rel] && flickrFeedsCache[rel].container) return flickrFeedsCache[rel].container; if (!flickrFeedsCache[rel]) { flickrFeedsCache[rel] = { container: null }; var tagsComma = rel.substring(4).replace('-', ','); $.getJSON('http://api.flickr.com/services/feeds/photos_public.gne?tags=' + tagsComma + '&tagmode=all&format=json&jsoncallback=?', function(data) { var container = $('<div/>').addClass('flickr-thumbs'); $.each(data.items, function(i, item) { $('<a/>') .attr('href', item.link) .append($('<img/>').attr('src', item.media.m)) .appendTo(container) .data('tip', '<strong>' + (item.title || '(no title)') + '</strong><br />by: ' + item.author.match(/\((.*)\)/)[1]); if (i == 4) return false; }); // add tips for the images inside the main tip container.find('a').poshytip({ content: function(){return $(this).data('tip');}, className: 'tip-yellowsimple', showTimeout: 100, alignTo: 'target', alignX: 'center', alignY: 'bottom', offsetY: 5, allowTipHover: false, hideAniDuration: 0 }); // store the content in the cache // and call updateCallback() to update the content in the main tooltip updateCallback(flickrFeedsCache[rel].container = container); } ); } return 'Loading images...'; } });