new Tooltip( [settings])
- A message that appears when a cursor is positioned over an element
- Each tooltip should have a unique
id
attribute to match the element'srel
attribute. - Nested tooltips are not supported.
- You can show tooltips via
data-tooltip
or JavaScript. - Valid align options are:
right
,left
,top
andbottom
to the element activating the tooltip overlay. - When setting
smart: true
, the tooltip will only detect collision withwindow
. - Custom tooltip based on
title
attribute. - Every tooltip element gets
MLTooltip
added to the element. - See it in action + some notes!
Parameters:
Name | Type | Argument | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
Object |
<optional> |
Configuration settings. Properties
|
Examples
<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>
<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.
// Will show the tooltip HTML with id of unique-id1 with a width of `50 pixels tooltips.show('unique-id1', {width: 50});
<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 id
String The id of the tooltip you want to display.
tooltipOptions
Object Configuration settings to overwrite defaults. Only
activeClass
,width
,arrow
andalign
will 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});