-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.tooltip.js
73 lines (56 loc) · 2.5 KB
/
jquery.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Part of Nitriques Solutions inc. (http://www.nitriques.com) jQuery plug-in bundle
* Liscence under the The Code Project Open License (CPOL)
* http://www.codeproject.com/info/cpol10.aspx
* Name: jquery.tooltip.js
* Date: 2010-02-15
* Version: 1.0
* Pre-requisites: none;
*/
(function($) {
$.fn.extend({ // jQuery plugin
ntr$tooltip: function() {
var config = {
tooltipCssClass: 'tooltip',
tooltipId: 'tooltip',
startYOffset: 100,
endYOffset: 30
};
var sel = $(this).selector; /* to use with .live() */
/* element-specific code here */
//this.each(function() {
//var t = $(this);
/* functions */
function on() {
var t = $(this);
var text = t.attr('alt') ? t.attr('alt') : t.attr('title');
/*alert('on ' + text);*/
$('body').append('<div id="' + config.tooltipId + '" class="' + config.tooltipCssClass + '">' + text + '</div>');
var defaultCss = { opacity: "0", position: 'absolute', maxWidth: '200px', top: (t.offset().top - config.startYOffset) + 'px', left: t.offset().left + 'px' };
$('div#' + config.tooltipId)
.css(defaultCss)
.stop(false, true) /* don't clear queue, do jump to end */
.animate({ opacity: "1", top: (t.offset().top - config.endYOffset - $('div#' + config.tooltipId).height()) + 'px' }, "slow");
return this;
};
function out() {
var t = $(this);
/*alert('out ' + text);*/
$('div#' + config.tooltipId).animate(
{ opacity: "0", top: (t.offset().top - config.startYOffset) + 'px' },
'fast',
'swing',
function() {
/* Once animation completed, remove from DOM */
$(this).remove();
return this;
});
};
$(sel).live('mouseenter', on); /* live doesn't work */
$(sel).live('mouseout', out);
//return this;
//});
return this;
}
});
})(jQuery);