-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.hoverbox.js
57 lines (50 loc) · 1.43 KB
/
jquery.hoverbox.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
56
57
/*
* jQuery Hoverbox 1.0
* http://koteako.com/hoverbox/
*
* Copyright (c) 2009 Eugeniy Kalinin
* Dual licensed under the MIT and GPL licenses.
* http://koteako.com/hoverbox/license/
*/
jQuery.fn.hoverbox = function(options) {
var settings = jQuery.extend({
id: 'tooltip',
top: 0,
left: 15
}, options);
var handle;
function tooltip(event) {
if ( ! handle) {
// Create an empty div to hold the tooltip
handle = $('<div style="position:absolute" id="'+settings.id+'"></div>').appendTo(document.body).hide();
}
if (event) {
// Make the tooltip follow a cursor
handle.css({
top: (event.pageY - settings.top) + "px",
left: (event.pageX + settings.left) + "px"
});
}
return handle;
}
this.each(function() {
$(this).hover(
function(e) {
if (this.title) {
// Remove default browser tooltips
this.t = this.title;
this.title = '';
this.alt = '';
tooltip(e).html(this.t).fadeIn('fast');
}
},
function() {
if (this.t) {
this.title = this.t;
tooltip().hide();
}
}
);
$(this).mousemove(tooltip);
});
};