easytooltip.js
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(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);