jQuery实例: ToolTip的实现

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>jQuery</title>
  6. <script type="text/javascript" src="jquery-1.2.6.pack.js"></script>
  7. <script type="text/javascript">
  8.     $(function(){
  9.       $("[myTip]").hover(function(){
  10.         $('<div id="luluTip"><div class="triangle" /></div>')
  11.         .insertAfter(this)
  12.         .prepend($(this).attr("myTip"));
  13.       $(this).mousemove(function(e){
  14.             ee=e || window.event;
  15.             var x=e.pageX-36;
  16.             if(x-2<0)
  17.                 x=2;
  18.             if(x+152>document.body.clientWidth)
  19.                 x=document.body.clientWidth-152;
  20.             $("#luluTip").css({"left":x,"top":e.pageY+18,"display":"block"});
  21.       });
  22.         },function(){
  23.             $("#luluTip").fadeOut('slow',function(){
  24.                 $(this).remove();
  25.             }); 
  26.     })
  27. });
  28. </script>
  29. <style type="text/css">
  30.     #luluTip
  31.     {
  32.         word-wrap:break-word; /**//*自动换行,在FF中对英文和数字无效*/
  33.         position:absolute;
  34.         width:150px;
  35.         color: #a00;
  36.         background-color:#FFFFCC;
  37.         border:1px solid #a00;
  38.         padding:10px;
  39.         display:none; /**//*我们先不要让它显示*/
  40.     }
  41.     #luluTip div.triangle /**//*后代选择器,选择ID为"luluTip"中DIV的类为"triangle"的元素*/
  42.     {
  43.         background:transparent
  44.             url('sj.gif')
  45.             no-repeat scroll left top;
  46.         position:absolute;
  47.         height:17px;
  48.         left:20px;
  49.         top:-16px;
  50.         width:31px;
  51.         z-index:999;
  52.     }
  53. </style>
  54. </head>
  55. <body>
  56. <input id="btnAjax" name="btnAjax" type="button" value="获取" myTip="sssssss" />
  57. <br/>
  58. <a myTip="这是要显示的内容!" href="#">sssssssssss</a> 
  59. </body>
  60. </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值