-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.on.tooltip.js
55 lines (50 loc) · 1.24 KB
/
jquery.on.tooltip.js
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
54
55
;(function($){
$.fn.tooltip = function(options) {
var
defaults = {
background: '#e3e3e3',
color: 'black',
borderColor: '#333',
borderRadius: 0,
offsetY: 10,
offsetX: 20
},
settings = $.extend({}, defaults, options);
this.each(function() {
var $this = $(this);
var title = this.title;
if($this.is('a') && $this.attr('title') != '') {
this.title = '';
$this.hover(function(e) {
// mouse over
$('<div id="tooltip" />')
.appendTo('body')
.text(title)
.hide()
.css({
backgroundColor: settings.background,
color: settings.color,
borderColor: settings.borderColor,
top: e.pageY + settings.offsetY,
left: e.pageX + settings.offsetX
})
.fadeIn(350);
if(settings.borderRadius > 0) {
$('#tooltip').css({borderRadius: settings.borderRadius + 'px'});
}
}, function() {
// mouse out
$('#tooltip').fadeOut(100).remove();
});
}
$this.mousemove(function(e) {
$('#tooltip').css({
top: e.pageY + settings.offsetY,
left: e.pageX + settings.offsetX
});
});
});
// returns the jQuery object to allow for chainability.
return this;
}
})(jQuery);