-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmTooltip.js
24 lines (21 loc) · 927 Bytes
/
mTooltip.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
(function ($) {
$.fn.mTooltip = function (options) {
this.each(function (i, e) {
var tooltipContent = $(e).attr('data-mTooltipText');
var tooltipBox = $();
var tempOffset = $(e).offset();
$(e).hover(function () {
tooltipBox = $('<div class="mTooltip">' + tooltipContent + '</div>').appendTo('body');
tooltipBox.hide();
var tooltipLeft = (tempOffset.left + $(e).outerWidth() / 2) - (tooltipBox.outerWidth() / 2);
var tooltipTop = tempOffset.top + $(e).outerHeight() / 2 + 20;
tooltipBox.css({position: 'absolute', left: tooltipLeft, top: tooltipTop});
tooltipBox.fadeIn();
}, function () {
tooltipBox.finish().fadeOut('fast', function () {
this.remove();
});
});
});
};
}(jQuery));