Created
July 1, 2012 16:21
-
-
Save monkeymonk/3028852 to your computer and use it in GitHub Desktop.
Easy Tooltip 1.0 - jQuery plugin
This file contains hidden or 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
/* | |
* Easy Tooltip 1.0 - jQuery plugin | |
* written by Alen Grakalic | |
* http://cssglobe.com/post/4380/easy-tooltip--jquery-plugin | |
* | |
* Copyright (c) 2009 Alen Grakalic (http://cssglobe.com) | |
* Dual licensed under the MIT (MIT-LICENSE.txt) | |
* and GPL (GPL-LICENSE.txt) licenses. | |
* | |
* Built for jQuery library | |
* http://jquery.com | |
* | |
*/ | |
(function($, window, undefined){ | |
$.fn.easyTooltip = function(options){ | |
// default configuration properties | |
var defaults = { | |
xOffset: 10 | |
, yOffset: 25 | |
, tooltipId: 'easyTooltip' | |
, clickRemove: false | |
, content: '' | |
, useElement: '' | |
}, content | |
options = $.extend(defaults, options) | |
return this.each(function(){ | |
var title = $(this).attr('title') | |
$(this).hover(function(e){ | |
content = (options.content != '') ? options.content : title | |
content = (options.useElement != '') ? $('#' + options.useElement).html() : content | |
$(this).attr('title', '') | |
if(content != '' && content != undefined){ | |
$('body').append('<div id="' + options.tooltipId + '">"' + content + '</div>') | |
$('#' + options.tooltipId).css({ | |
position: 'absolute' | |
, top: (e.pageY - options.yOffset) + 'px' | |
, left: (e.pageX + options.xOffset) + 'px' | |
, display: 'none' | |
}) | |
.fadeIn('fast') | |
} | |
}, function(){ | |
$('#' + options.tooltipId).remove() | |
$(this).attr('title', title) | |
}) | |
.mousemove(function(e){ | |
$('#' + options.tooltipId).css({ | |
top: (e.pageY - options.yOffset) + 'px' | |
, left: (e.pageX + options.xOffset) + 'px' | |
}) | |
}) | |
if(options.clickRemove){ | |
$(this).mousedown(function(e){ | |
$('#' + options.tooltipId).remove() | |
$(this).attr('title', title) | |
}) | |
} | |
}) | |
} | |
})(jQuery, window) |
Hi,
I have implemented this js. but getting duplicate tooltip on the window.
Please suggest some resolution.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can I add negative value for the X&Y position?