html代码

<a href=”http://www.shangzh.com” class=”tooltiptitle=”老李的博客”>尚站互联首页</a>

js代码

//鼠标跟随
var x = 15;
var y = 10;
$("body").append("<div id='tooltip' style='position: absolute;border: #333 1PX solid;background: #f7f5d1;padding: 1px;color: #333;display: none;padding: 1px;'></div>");
var mytooltip = $("#tooltip");

$(".tooltip").mouseover(function (e) { //当鼠标指针从元素上移入时
   this.mytitle = this.title;
   this.title = '';
   mytooltip.html(this.mytitle).css({ "top": (e.pageY + y) + "px", "left": (e.pageX + x) + "px" }).show("fast");
}).mouseout(function () { //当鼠标指针从元素上移开时
   this.title = this.mytitle;
   mytooltip.html('');
}).mousemove(function (e) { //当鼠标指针从元素上移动时
   mytooltip.css({ "top": (e.pageY + y) + "px", "left": (e.pageX + x) + "px" });
});

Comments are closed.

Post Navigation