new Tooltip( [settings])
- A message that appears when a cursor is positioned over an element
- Each tooltip should have a unique
idattribute to match the element'srelattribute. - Nested tooltips are not supported.
- You can show tooltips via
data-tooltipor JavaScript. - Valid align options are:
right,left,topandbottomto the element activating the tooltip overlay. - When setting
smart: true, the tooltip will only detect collision withwindow. - Custom tooltip based on
titleattribute. - Every tooltip element gets
MLTooltipadded to the element. - See it in action + some notes!
Parameters:
| Name | Type | Argument | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
Object |
<optional> |
Configuration settings. Properties
|
Examples
Sample markup of tooltip HTML.
<div class="tooltip" id="unique-id1">
<div class="tooltip-content">
<h1 class="tight">Hello! I am a tooltip</h1>
<p class="tight">Im some text about the tooltip.</p>
</div>
</div>
You can show tooltips via data attribute, data-tooltip="width:200:align:bottom".
The only lines of JavaScript would be two lines. The rel attribute needs to equal
the ID of the tooltip HTML element.
<a href="#" rel="unique-id1" data-tooltip="width:200:align:bottom">open modal</a>
// Only JavaScript needed:
<script>
var tooltips = new ML.Tooltip({
delay: true
});
tooltips.init();
</script>
// Other javascript files go here.
The tooltip can be triggered via JavaScript instead of or in addition
to data-tooltip
// Will show the tooltip HTML with id of unique-id1 with a width of `50 pixels
tooltips.show('unique-id1', {width: 50});
Dynamic tooltip that shows a tooltip with the content "I am a tooltip" inside.
<a href="#" data-tooltip="smart:true:delay:true" title="I am a tooltip">tooltip link</a>
Methods
-
destroy()
-
Destroys the tooltip init.
Example
tooltips.destroy();
-
hide()
-
Hides all the tooltips.
Example
tooltips.hide();
-
init()
-
Initializes the tooltip class.
Example
tooltips.init();
-
show(id, tooltipOptions)
-
Shows a tooltip. Used when showing a tooltip without
data-tooltip.Parameters:
Name Type Description idString The id of the tooltip you want to display.
tooltipOptionsObject Configuration settings to overwrite defaults. Only
activeClass,width,arrowandalignwill be overriden. Other settings are ignored.Example
// Shows the tooltip with id of unique-id1 with a width of 300 pixels. tooltips.show('unique-id1', {width: 400});