Jquery实现ToolTip之元素定位

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>无标题页</title>
    <script type="text/javascript" src="JS/jquery-1.3.2.min.js" ></script>
    <script type="text/javascript">
       function ShowTip(event,obj,message)
       {
          var xOffset = -10; // x distance from mouse
          var yOffset = 10; // y distance from mouse    
         
          //obj.style.top = (event.clientX + yOffset)+"px";
          //obj.style.left = (event.clientY + xOffset)+"px";
          //获取元素width: $(obj).width();
          //获取元素height:$(obj).height()
          
          //获取元素位置:$(obj).position().top和$(obj).offset().top
          
          $('body').append( '<div id="tipmessage">'+message+'</div>');
          $('div#tipmessage').css("top", $(obj).position().top+$(obj).height() + "px").css("left", $(obj).position().left+"px").fadeIn("slow");
       }
       
       function HideTip()
       {
         $("div#tipmessage").fadeOut("slow").remove();
       }
       
    </script>
    <style type="text/css">
      #tipmessage
      {
        display:none;
        z-index:1000;
        border:1px solid #448833;
        position:absolute;
        background:#ffffff;
        max-width:200px;
        max-height:30px;
        padding:5px 10px;
      }
    </style>
</head>
<body>
<a href="#" οnmοuseοver="ShowTip(event,this,'aaaaaaaaa')" οnmοuseοut="HideTip()">Tip</a>
</body>
</html>

转载于:https://www.cnblogs.com/hubcarl/archive/2010/09/26/1835396.html

评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符 “速评一下”
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页