用Jquery写的hover时的Tip提示

这篇博客介绍了如何使用Jquery在鼠标悬停(hover)时创建Tip提示效果。通过结合CSS样式和JavaScript代码,实现了交互式的用户体验。
有时写表格时有些东西一行肯定显示不完,比如一个对象有20多个属性,很长的备注等等,就可以用hover时的悬浮提示来显示
我实现的效果如图,当然tip窗就是个div,可以自己写很多css样式来美化
写在这方便自己下次用,免得忘了
![简单的tip提示](https://img-blog.youkuaiyun.com/20150625193637513)

界面代码

<table width="200" border="1">
<thead>
  <tr>
    <th scope="col">学号</th>
    <th scope="col">姓名</th>
    <th scope="col">性别</th>
  </tr>
</thead>
<tbody>
  <tr>
    <th scope="row">124124</th>
    <td>哈哈</td>
    <td></td>
    <td class='hidden-detail'>我是Tip  哈哈,我是一个<b>好人</b>,我的电话是123456578,别忘联系我哦</td>
  </tr>
  <tr>
    <th scope="row">324134</th>
    <td>嘻嘻</td>
    <td>嘻嘻</td>
    <td class='hidden-detail'>我是Tip  嘻嘻,我是一个<b>坏人</b></td>
  </tr>
</tbody>
</table>

css代码

    .tip{
        position:absolute;
        background:#9FC;
        border-color:#F60;
        z-index:9999;
        filter:alpha(opacity=80);  
        -moz-opacity:0.8;  
        -khtml-opacity: 0.8;  
        opacity: 0.8;  
    }
    .hidden-detail{
        display:none;
    }

javacript

$(function(){
        var tip="";
        $("table tbody tr").hover(function(e){
            tip="<div class='tip'>"+$(this).children("td:last").text()+"</div>";
            $("body").append(tip);
            $(".tip").css({"top":e.pageY+"px","left":e.pageX+"px"}).show(1000);
            $(this).mousemove(function(e){
                $(".tip").css({"top":e.pageY+"px","left":e.pageX+"px"}).show(1000);
            });
        },function(){
            $(".tip").remove();    
        });
    });
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值