Created
April 18, 2012 14:17
-
-
Save timmahoney/2413880 to your computer and use it in GitHub Desktop.
jQuery Tooltip plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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