1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
/*
* dvjhTooltip
*
* Généralisation du script de Alen Grakalic (http://cssglobe.com)
* http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
*
* Le tag à commenté doit possédé les attributs : class="tooltip" et title="Un commentaire."
*
* CSS, il faut définir le style du paragraphe de commentaire et d'id="tooltip".
* Exemple de CSS :
* .tooltip {}
* #tooltip{position:absolute; border:1px solid #CC6666; background-color:#CCFFCC; padding:6px; color:#000000; display:none; z-index:9999;}
*
* Usage : $("*").dvjhTooltip();
*/
(function($){
$.fn.dvjhTooltip = function(options) {
var opts = $.extend({}, $.fn.dvjhTooltip.defaults, options);
return this.each(function(){
if (($(this).hasClass($.fn.dvjhTooltip.defaults.needClass)) && ($(this).attr("title") != "")) {
var tag = $(this).get(0).tagName.toLowerCase();
$(this).attr("dvjh", $(this).attr("title"));
$(tag + "." + $.fn.dvjhTooltip.defaults.needClass).hover(
function(e){
$(this).attr("title","");
$("body").append("<p id='tooltip'>"+ $(this).attr("dvjh") +"</p>");
$("#tooltip")
.css("top",(e.pageY - $.fn.dvjhTooltip.defaults.xOffset) + "px")
.css("left",(e.pageX + $.fn.dvjhTooltip.defaults.yOffset) + "px")
.fadeIn("fast");
},
function(){
$(this).attr("title", $(this).attr("dvjh"));
$("#tooltip").remove();
}
);
$(tag + "." + $.fn.dvjhTooltip.defaults.needClass).mousemove(function(e){
$("#tooltip")
.css("top",(e.pageY - $.fn.dvjhTooltip.defaults.xOffset) + "px")
.css("left",(e.pageX + $.fn.dvjhTooltip.defaults.yOffset) + "px");
});
}
});
};
$.fn.dvjhTooltip.defaults = {
xOffset: 10,
yOffset: 20,
needClass: "tooltip"
};
})(jQuery); |
Partager