Highly customizable Tool-tip Mootools class that allows for arbitrary and dynamic tip HTML and provides lots of events to hook into for tip showing/hiding/placement.
Each instance of JustTheTip creates only one element and positions it absolutely. You can use the events to change the HTML of the tip based on the element that is being interacted with. The interaction defaults to mouseenter but this is configurable.
You can either pass in a selector or an elements array to specify which elements will get tooltips, or you can pass in just one element (even document.body) and use Event.Delegation to specify which elements get tips. The latter approach is much more efficient as it adds only one event.
You can add elements to a given JustTheTip instance whenever you want.
You can also turn tips on/off for a given element at your discretion.
It's easiest to just show examples of what you can do, so I'll start with a basic one:
new JustTheTip('.needs-tip', { tip_html : 'You will never see this.', show_delay : 0, hide_delay : 100, fade_in_duration : 500, fade_out_duration : 1000, position: {position: 'bottomLeft'}, onTipShown: function(tip,elem,jtt){ tip.set('html', elem.get('html') + " tip"); }, shouldShowTip: function(elem){ return elem.get('html').test(/brawndo/); } });
This instance of JustTheTip will cause the following to happen: All elements with the class 'needs-tip', when mouseenter'd, will get a tooltip at their bottom-left whose contents are the same as the hovered element, plus " tip". But only if the element's html contains the string "brawndo". The tip will start to fade in immediately, but will start to fade out only after the mouse has left the tip & element for 100 miliseconds.
Let's look at an example that uses Event.Delegate:
new JustTheTip($('article_body'), { tip_html : "<a class='tip-preview-link'>preview</a>", tip_class : 'article-link-tip', show_delay : 100, show_event : 'mouseover:relay(a.wikilink)', position: {position: 'centerRight', edge: 'centerLeft', offset: {x: 20, y: 30}}, onTipShown: function(tip,elem,jtt){ tip.getFirst('.tip-preview-link').set('href', elem.get('href') + '/preview') }
});
This instance will make a tip, with initial html/class as specified, show after the user has mouseover'd an anchor tag with the class 'wikilink' for 100 miliseconds within the element #article_body. When it is shown the link inside the tip will get an href based on the mouseover'd element. The center left side of the tip will be placed against the center right of the element with the given offsets.
For a demo of this an other tips, check http://www.bing.com/reference/semhtml/Achewood and hover over some links in the article. The first tip is what you see above, which has its own tip whose content is loaded with a Request.
Full documentation below:
new JustTheTip(elements, [options])
1. element - (mixed) An Element, an array of Elements or a CSS Selector. 2. options - (object, optional) the options described below:
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus