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
|
function tooltip(){
xOffset = 10;
yOffset = -20;
widthTip = 250; /* Largeur des tooltip par defaut. sinon c'est l'attribut REL ou ALT definissant sa taille */
// $("a.tooltip").unbind(); // Detruit les traces des precedents evenements pour eviter les empilements d'evenements.
$(".tooltip").bind("mouseenter", function(e){
if (this.alt) widthTip = parseInt(this.alt);
if (this.rel) widthTip = parseInt(this.rel);
this.widthBody = $("body").width();
this.coordX = e.pageX;
this.t = this.title;
this.title = "";
construct="<div id='tooltip'>";
construct+="<div class='toolTitle'>"+ this.t +"</div>";
construct+="<div class='toolContent'>"+ widthTip +"</div>";
construct+="</div>";
$("body").append(construct);
$("#tooltip")
.css("font-style", "italic")
.css("top",(e.pageY - yOffset) + "px")
.css("left",(e.pageX + xOffset) + "px")
.css("opacity", "0.85")
.fadeIn("normal");
});
$(".tooltip").bind("mouseleave", function(e){
this.title = this.t; // Restaure le title du <a href>
$("#tooltip").remove();
widthTip = 250; /* pour les tooltip n'ayant pas de taille predefinie par les balises alt ou rel */
});
$(".tooltip").bind("mousemove", function(e){
if ( this.widthBody-e.pageX > ( widthTip + 50 ) ) {
$("#tooltip")
.css("top",(e.pageY - yOffset) + "px")
.css("left",(e.pageX + xOffset) + "px")
.css("width", widthTip + "px");
} else {
$("#tooltip")
.css("top",(e.pageY - yOffset) + "px")
.css("left",(e.pageX - ( widthTip + 30 ) + xOffset) + "px")
.css("width", widthTip + "px");
}
});
} |
Partager