Created
August 7, 2016 18:16
-
-
Save zaurmag/80124b9e9ccd643b38043f412b0faeab to your computer and use it in GitHub Desktop.
Плагин подсказки Tooltip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ======= Tooltip ======= | |
(function($) { | |
$.fn.easyTooltip = function(options) { | |
// default configuration properties | |
var defaults = { | |
xOffset: 10, | |
yOffset: 25, | |
tooltipId: "easyTooltip", | |
clickRemove: false, | |
content: "", | |
useElement: "" | |
}; | |
var options = $.extend(defaults, options); | |
var content; | |
this.each(function() { | |
var title = $(this).attr("data-tooltip"); | |
var bg = $(this).attr("data-tooltip-bg"); | |
$(this).hover(function(e) { | |
content = (options.content != "") ? options.content : title; | |
content = (options.useElement != "") ? $("#" + options.useElement).html() : content; | |
$(this).attr("data-tooltip", ""); | |
if (content != "" && content != undefined) { | |
$("body").append("<div id='" + options.tooltipId + "'>" + content + "</div>"); | |
$("#" + options.tooltipId) | |
.css("position", "absolute") | |
.css("top", (e.pageY + options.yOffset) + "px") | |
.css("left", (e.pageX + options.xOffset) + "px") | |
.css("display", "none") | |
.fadeIn("fast") | |
} | |
if (bg != "" && bg != undefined) { | |
$('#' + options.tooltipId).addClass(bg); | |
} | |
}, | |
function() { | |
$("#" + options.tooltipId).remove(); | |
$(this).attr("data-tooltip", title); | |
}); | |
$(this).mousemove(function(e) { | |
$("#" + options.tooltipId) | |
.css("top", (e.pageY + options.yOffset) + "px") | |
.css("left", (e.pageX + options.xOffset) + "px") | |
}); | |
if (options.clickRemove) { | |
$(this).mouseleave(function(e) { | |
$("#" + options.tooltipId).remove(); | |
$(this).attr("data-tooltip", title); | |
}); | |
} | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment