Skip to content

Instantly share code, notes, and snippets.

@timmahoney
Created April 18, 2012 14:17
Show Gist options
  • Save timmahoney/2413880 to your computer and use it in GitHub Desktop.
Save timmahoney/2413880 to your computer and use it in GitHub Desktop.
jQuery Tooltip plugin
(function( $ ) {
$.fn.tooltip = function() {
/* CONFIG */
xOffset = 10;
yOffset = 20;
// these 2 variable determine popup's distance from the cursor
// you might want to adjust to get the right result
/* END CONFIG */
$(this).hover( function(e){
this.t = this.title;
this.title = "";
$("body").append("<p id='tooltip'>"+ this.t +"</p>");
$("#tooltip")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
},
function(){
this.title = this.t;
$("#tooltip").remove();
});
$(this).mousemove( function(e){
$("#tooltip")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
};
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment