Created
February 18, 2009 20:20
-
-
Save rpheath/66517 to your computer and use it in GitHub Desktop.
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
// tooltip plugin for jQuery | |
(function($) { | |
$.fn.tooltip = function(options) { | |
var options = $.extend({ | |
xOffset: 30, | |
yOffset: 7, | |
follow: false | |
}, options) | |
return this.each(function() { | |
$(this).hover(function(e) { | |
// prevent duplicate "hovers" | |
this._title = this.title | |
this.title = '' | |
$('body').append('<p id="tooltip">' + this._title + '</p>') | |
$('#tooltip'). | |
css('top', (e.pageY - options.yOffset) + 'px'). | |
css('left', (e.pageX + options.xOffset) + 'px'). | |
fadeIn('fast') | |
}, function() { | |
this.title = this._title | |
$('#tooltip').remove() | |
}) | |
// supports the option to follow the | |
// tooltip wherever the cursor goes | |
if (options.follow) { | |
$(this).mousemove(function(e) { | |
$('#tooltip'). | |
css('top', (e.pageY - options.yOffset) + 'px'). | |
css('left', (e.pageX + options.xOffset) + 'px') | |
}) | |
} | |
}) | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment