<!-- Throw in a nice looking font just for the fun of it -->
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:400,700,300,200"/>
<p><a href="#" class="tooltip" id="item7">Lorem ipsum</a> dolor sit amet, consectetur adipiscing elit. Donec suscipit, ante id porttitor faucibus, <a href="#" class="tooltip" id="item6">odio eros</a> pellentesque sapien, at consectetur mi nibh at massa.</p>
<ul>
<li><a href="#" class="tooltip" id="item1">Lorem Ipsum 1</a></li>
<li><a href="#" class="tooltip" id="item2">Lorem Ipsum 2</a></li>
<li><a href="#" class="tooltip" id="item3">Lorem Ipsum 3</a></li>
<li><a href="#" class="tooltip" id="item4">Lorem Ipsum 4</a></li>
<li><a href="#" class="tooltip" id="item5">Lorem Ipsum 5</a></li>
<li><a href="#" class="tooltip" id="item6">Lorem Ipsum 6</a></li>
</ul>
<!-- The Tool-Tip -->
<div class="tip tooltip">
<div class="center"></div>
</div>
function Tooltip(elementClass, tipMessages) {
var obj = this;
this.m_class = elementClass;
this.m_messages = tipMessages;
this.m_tipDiv = $(".tip."+elementClass);
this.show = function () {
// Get the Tool-Tip text from the associative array
var message = obj.m_messages[$(this).attr("id")];
if (!message) message = "Tip undefined for "+$(this).attr("id");
// Slide in the tooltip
obj.m_tipDiv.show().css("top",$(this).offset().top - 40)
.stop(true,false).animate({left: $(this).offset().left + ($(this).width() / 2) - 16})
.find('.center').html(message);
}
this.hide = function () {
// Make the tooltip slide out
obj.m_tipDiv.stop(true,false).animate({left: -300});
}
$("." + this.m_class).mouseover(this.show).mouseout(this.hide);
this.m_tipDiv.css("display","none");
}
// Add your Tool-Tips here. Format: item#: "Tool-Tip Text", then add the item# as the id to any href.
$(document).ready(function () {
var tips = { item1: "Tool-Tips Slide in",
item2: "You can add as many as you like",
item3: "The Tool-Tip text is defined...",
item4: "in the $(document).ready(function ())",
item5: "Nice Tool-Tip!",
item6: "You can also re-use a Tool-Tip",
item7: "You can add Tool-Tips anywhere easily.",
};
new Tooltip('tooltip',tips);
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.