Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created April 18, 2009 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisasann/97764 to your computer and use it in GitHub Desktop.
Save hisasann/97764 to your computer and use it in GitHub Desktop.
(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