Skip to content

Instantly share code, notes, and snippets.

@megaxorg
Created March 25, 2013 12:13
Show Gist options
  • Save megaxorg/5236729 to your computer and use it in GitHub Desktop.
Save megaxorg/5236729 to your computer and use it in GitHub Desktop.
<a href="#" class="tooltip" title="Content of the tooltip"> Style with #tooltip
function tooltip(obj) {
if (!obj.length) return;
$("body").append('<div id="tooltip" />');
var tooltip = $("#tooltip");
var title;
obj.hover(function() {
title = $(this).attr("title") ? $(this).attr("title") : "No Title";
$(this).attr("title","");
tooltip.html(title);
tooltip.stop(true,true).delay(50).fadeIn("slow").dequeue();
},function() {
$(this).attr("title",title);
tooltip.stop(true,true).fadeOut("slow");
}).mousemove(function(e) {
tooltip.animate({
top:e.pageY + 10,
left:e.pageX + 10
},200);
});
}
jQuery(document).ready(function(){
tooltip($(".tooltip"));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment