Created
April 18, 2009 20:12
-
-
Save hisasann/97764 to your computer and use it in GitHub Desktop.
This file contains 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
(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