话不多说,直接放代码,效果见本站a标签效果:
js代码:
//tooltip
tooltip();
function tooltip() {
$("a,div,li,h3,h4,img,i").each(function() {
$("#tooltip").remove();
if (this.title) {
var a = this.title;
$(this).mouseover(function(b) {
this.title = "";
$("body").append('<div id="tooltip">' + a + "</div>");
$("#tooltip").css({
left: b.pageX - 15 + "px",
top: b.pageY + 30 + "px",
opacity: "0.8"
}).fadeIn(250)
}).mouseout(function() {
this.title = a;
$("#tooltip").remove()
}).mousemove(function(a) {
$("#tooltip").css({
left: a.pageX - 15 + "px",
top: a.pageY + 30 + "px"
})
})
}
})
}
css样式代码:
#tooltip{position:absolute;z-index:9999;display:none;padding:4px 8px;border:1px solid rgba(255,255,255,0.25);border-radius:3px;background-color:#0c0;color:#fff;text-align:center;font-size:12px;}
#tooltip:before{position:absolute;top:-6px;left:15px;width:0;height:0;border:6px dashed #0c0;border-top:0;color:#fff;content:' ';line-height:0;border-bottom-style:solid;border-left-color:transparent;border-right-color:transparent;}