Create a gist now

Instantly share code, notes, and snippets.

(function($) {
var id = "altTip", // Tip id
$this, // Target elem
opts = {
addClass: null
};
$.fn.jAltTip = function(options) {
$.extend(opts, options);
$this = this;
if (!$("#" + id).length)
// Tip html create
$("<div>")
.attr("id", id)
.css({
position: "absolute",
display: "none"
})
.appendTo("body");
var elem = $("#" + id)
margin = 10,
opacity = 0.8;
if (opts.addClass)
elem.addClass(opts.addClass);
else
elem.css({
backgroundColor: "#888"
})
// Event setter
$($this)
.hover(function(e) {
elem.css({
top: e.pageY + margin + "px", left: e.pageX + margin + "px",
opacity: opacity, padding: "10px"
})
.html($(this).attr("alt") ? $(this).attr("alt")
: $(this).attr("title") ? $(this).attr("title") :
$(this).html())
.fadeIn(200);
}, function(e) {
elem
.fadeOut(100);
})
.mousemove(function(e) {
elem.css({
top: e.pageY + margin + "px", left: e.pageX + margin + "px"
})
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment