The tooltip supports flexibility in how it is triggered, closed, and how its content is loaded:
Basic A little spice
Content from another element
The tooltip displays content from another element on the page.
<span class="tooltip" onmouseover="tooltip.pop(this, '#demo2_tip', {position:0, cssClass:'no-padding'})">
Content from another element
</span>
<div style="display:none;">
<div id="demo2_tip">
<img src="tooltip-head.jpg" />
<div style="padding: 20px">
<h3>Rich HTML content</h3>
<p>The tooltip displays content from another element on the page.</p>
</div>
</div>
</div>
<a href="#" onclick="tooltip.pop(this, '#demo3_tip', {overlay:1, position:4}); return false;">Click me</a>
<div style="display:none;">
<div id="demo3_tip">
<form action="javascript-tooltip" method="post">
Name: <input type="text" name="name" />
<input type="submit" value="Login" />
<input type="button" value="Cancel" onclick="tooltip.hide()" />
</form>
</div>
</div>
Load all content from another page
Load page fragment from another page
<span class="tooltip"
onmouseover="tooltip.ajax(this, 'src/tooltip-ajax.html')">
Load all content from another page
</span>
<span class="tooltip"
onmouseover="tooltip.ajax(this, 'src/tooltip-ajax.html#div2')">
Load page fragment from another page
</span>
<script type="text/javascript">
var myAjaxSetting = {
context: { index: -1 },
success: myCallback,
responseType: 'json',
};
function myCallback(response, context) {
var x = JSON.parse(response).catalog[context.index];
var title = x.title;
var artist = x.artist;
var price = x.price;
var image = '<img src="src/tooltips-cd' + context.index + '.jpg" style="float:right;margin-left:12px;width:75px;height:75px;" />';
return "<div style='width:220px;'>" + image + '<b>' + title + '</b><br /><i>' + artist + "</i><br /><br />Price: <span class='red'>$" + price + '</span></div>';
}
</script>
<img
src="src/tooltips-cd1.jpg"
onmouseover="myAjaxSetting.context.index = 1; tooltip.ajax(this, 'src/products.json', myAjaxSetting, { position:0, effect:'slide' });"
/>
...(The 2nd and 3rd <img> tags are omitted for brevity.)
<img
src="src/tooltips-cd4.jpg"
onmouseover="myAjaxSetting.context.index = 4; tooltip.ajax(this, 'src/products.json', myAjaxSetting, { position:0, effect:'slide' });"
/>
You can configure the tooltip global options by editing the var tooltipOptions in tooltip.js.
Note: To set different options for an individual tooltip, pass a specific options object when opening it, as shown in the demos above.
var tooltipOptions=
{
position: 1,
smartPosition: false,
maxWidth: 500,
sticky: false,
overlay: false,
// In most cases, you don't need to change the following options.
relativeTo: "element",
cssClass: "",
offsetX: 0,
offsetY: 0,
calloutPosition: 0.3,
calloutSize: 20,
showDelay: 150,
hideDelay: 300,
effect: "slide",
duration: 200
};
You can modify tooltip.css directly to change the appearance of all tooltips globally.
If you want to apply custom styling to a specific tooltip only, pass the cssClass option when opening it. The specified class will be added to the div#mcTooltip element.
To better understand how the styles can be customized, refer to the sample tooltip markup below, which is generated by the tooltip.js script.
<div id="mcTooltipWrapper">
<div id="mcTooltip">
<div class="mcTooltipInner">
(Tooltip content)
</div>
</div>
<div id="mcttCo"></div>
<div id="mcttCloseButton"></div>
</div>
<div id="mcOverlay"></div> 