jQuery实现鼠标移上弹出提示框,移出消失

<TD>里有一行数据 “那片笑声让我想起......”  假设超出规定长度将用......代替,

而现在要通过鼠标移动到......上 显示全部内容,移出则消失。如下图:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <a href='#' onMouseOver='mouseOver(this,event,"+s+");' onMouseOut='mouseOut();'>.....</a>  
  2. //data是提示框要显示的全部内容  

CSS

[css]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. .tooltip {  
  2.   positionabsolute;  
  3.   displaynone;  
  4.   z-index9900000;  
  5.   outlinenone;  
  6.   padding5px;  
  7.   border-width1px;  
  8.   border-stylesolid;  
  9.   border-radius: 5px;  
  10.   -moz-border-radius: 5px 5px 5px 5px;  
  11.   -webkit-border-radius: 5px 5px 5px 5px;  
  12.   border-radius: 5px 5px 5px 5px;  
  13. }  

[javascript]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. function mouseOver(t,e,data){  
  2.      //参数含义    
  3.      //t:指当前对象,即超链接<a>  
  4.      //e:event事件  
  5.      //data:要显示的内容  
  6.      var tooltipHtml = "<div id='tooltip' class='tooltip'>"+data+"</div>";  
  7.      $(t).append(tooltipHtml); //添加到页面中    
  8.      $("#tooltip").css({    
  9.           "top": (e.pageY) + "px",    
  10.           "left": (e.pageX) + "px"   
  11.      }).show("fast"); //设置提示框的坐标,并显示   
  12. }  
  13. function mouseOut(){  
  14.      $("#tooltip").remove();    
  15. }  


-----------------------华丽的分割线------------------------------

另一种方法:

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <a id="myTip">鼠标移在我上面有惊喜!</a>  

[javascript]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $(document).ready(function(){  
  2.     $("#myTip").mouseover(function(event){  
  3.         var tooltipHtml = "<div id='tooltip' class='tooltip'>Hello!</div>";  
  4.         $(this).append(tooltipHtml);  
  5.          $("#tooltip").css({    
  6.              "top": (event.pageY) + "px",    
  7.              "left": ($(this).width()) + "px"  //紧跟在内容的后面  
  8.          }).show("fast"); //设置提示框的坐标,并显示   
  9.     }).mouseout(function(){  
  10.         $("#tooltip").remove();  
  11.     })  
  12. })  

$(this) :获得当前对象
$(this).width() :获得当前对象的宽度值

event.pageY  :事件在网页中的y轴坐标


转自http://blog.csdn.net/itmyhome1990/article/details/17955543

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值