jquery实现图片跟随鼠标

        开发后台写页面困难的一比啊,想写个鼠标移动某连接右侧显示二维码,并跟随鼠标移动的功能,各种查资料,花了一小天终于搞出来了,代码的记下来,浪费了我这么多时间,记你一辈子,这个可以直接在W3School直接运行,可以根据某行显示某个特定的图片,自己定义就行

<html>
<head>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>jquery图片跟随鼠标</title>
    <script type="text/javascript">
        function hideImg(num){
            if(num.className == "1_name"){
                $('#1_erweima').hide();
            }else if(num.className == "2_name"){
                $('#2_erweima').hide();
            }
        }

        function showImg(num) {
            var intX = window.event.clientX;
            var intY = window.event.clientY;
            if (num.className == "1_name") {
                $('#1_erweima').css("left", intX + 20 + "px");
                $('#1_erweima').css("top", intY + 10 + "px");
                $('#1_erweima').show();
            } else if (num.className == "2_name") {
                $('#2_erweima').css("left", intX + 20 + "px");
                $('#2_erweima').css("top", intY + 10 + "px");
                $('#2_erweima').show();
            }
        }
    </script>
</head>
<body>
<table>
    <tr>
        <th>
            <a href="https://www.baidu.com/" class="1_name" target="_blank" οnmοuseοut="hideImg(this)" οnmοusemοve="showImg(this)" οnmοuseοver="showImg(this)" style="color: #1192cc;">我是百度,会跟随</a>
        </th>
    </tr>
    <tr>
        <th>
            <a href="https://www.baidu.com/" class="1_name" target="_blank" style="color: #1192cc;">我是百度</a>
        </th>
    </tr>
    <tr>
        <th>
            <a href="https://www.baidu.com/" class="2_name" target="_blank" οnmοuseοut="hideImg(this)" οnmοusemοve="showImg(this)" οnmοuseοver="showImg(this)" style="color: #1192cc;">我也是百度,也跟随</a>
        </th>
    </tr>
    <div id="1_erweima" style="display:none;right:20;position:absolute;">
        <img src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top_ca79a146.png" />
    </div>
    <div id="2_erweima" style="display:none;right:20;position:absolute;">
        <img src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top_ca79a146.png" />
    </div>
</table>
</body>
</html>


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值