jquery实现图片跟随鼠标的实例


Posted in jQuery onOctober 17, 2017

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/" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="1_name" target="_blank" onmouseout="hideImg(this)" onmousemove="showImg(this)" onmouseover="showImg(this)" style="color: #1192cc;">我是百度,会跟随</a> 
    </th> 
  </tr> 
  <tr> 
    <th> 
      <a href="https://www.baidu.com/" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="1_name" target="_blank" style="color: #1192cc;">我是百度</a> 
    </th> 
  </tr> 
  <tr> 
    <th> 
      <a href="https://www.baidu.com/" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="2_name" target="_blank" onmouseout="hideImg(this)" onmousemove="showImg(this)" onmouseover="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>

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

jQuery 相关文章推荐
jQuery插件HighCharts绘制简单2D折线图效果示例【附demo源码】
Mar 21 jQuery
jQuery使用unlock.js插件实现滑动解锁
Apr 04 jQuery
jQuery.Sumoselect插件实现下拉复选框效果
Nov 09 jQuery
前端html中jQuery实现对文本的搜索功能并把搜索相关内容显示出来
Nov 14 jQuery
利用JQUERY实现多个AJAX请求等待的实例
Dec 14 jQuery
jQuery zTree搜索-关键字查询 递归无限层功能实现代码
Jan 25 jQuery
jQuery动态添加li标签并添加属性和绑定事件方法
Feb 24 jQuery
jQuery实现的3D版图片轮播示例【滑动轮播】
Jan 18 jQuery
jquery css实现流程进度条
Mar 26 jQuery
jquery绑定事件 bind和on的用法与区别分析
May 22 jQuery
jQuery使用jsonp实现百度搜索的示例代码
Jul 08 jQuery
jQuery实现电梯导航模块
Dec 22 jQuery
jquery一键控制checkbox全选、反选或全不选
Oct 16 #jQuery
jQuery实现简单的回到顶部totop功能示例
Oct 16 #jQuery
Django中使用jquery的ajax进行数据交互的实例代码
Oct 15 #jQuery
jQuery实现的页面遮罩层功能示例【测试可用】
Oct 14 #jQuery
jQuery响应滚动条事件功能示例
Oct 14 #jQuery
jQuery实现的鼠标滚轮控制图片缩放功能实例
Oct 14 #jQuery
jQuery结合jQuery.cookie.js插件实现换肤功能示例
Oct 14 #jQuery
You might like
详解php的socket通信
2015/08/11 PHP
基于PHP+jQuery+MySql实现红蓝(顶踩)投票代码
2015/08/25 PHP
php使用curl通过代理获取数据的实现方法
2016/05/16 PHP
php微信公众账号开发之前五个坑(一)
2016/09/18 PHP
linux平台编译安装PHP7并安装Redis扩展与Swoole扩展实例教程
2016/09/30 PHP
浅析PHP中的闭包和匿名函数
2017/12/25 PHP
PHP正则表达式处理函数(PCRE 函数)实例小结
2019/05/09 PHP
javascript this详细介绍
2016/09/19 Javascript
关于Vue.nextTick()的正确使用方法浅析
2017/08/25 Javascript
bootstrap里bootstrap动态加载下拉框的实例讲解
2018/08/10 Javascript
js中Generator函数的深入讲解
2019/04/07 Javascript
vue和iview实现Scroll 数据无限滚动功能
2019/10/31 Javascript
[54:28]EG vs OG 2019国际邀请赛小组赛 BO2 第一场 8.16
2019/08/18 DOTA
python 获取et和excel的版本号
2009/04/09 Python
Python set集合类型操作总结
2014/11/07 Python
python通过字典dict判断指定键值是否存在的方法
2015/03/21 Python
Python中函数eval和ast.literal_eval的区别详解
2017/08/10 Python
python 读取竖线分隔符的文本方法
2018/12/20 Python
Python 微信之获取好友昵称并制作wordcloud的实例
2019/02/21 Python
Python 根据数据模板创建shapefile的实现
2019/11/26 Python
CSS3中设置3D变形的transform-style属性详解
2016/05/23 HTML / CSS
解析HTML5中的新功能本地存储localStorage
2016/03/01 HTML / CSS
Bose法国官网:购买耳机、扬声器、家庭影院、专业音响
2017/12/21 全球购物
L’urv官网:精品女性运动服品牌
2019/07/07 全球购物
凌阳科技股份有限公司C++程序员面试题笔试题
2014/11/20 面试题
初级会计求职信范文
2014/02/15 职场文书
励志演讲稿200字
2014/08/21 职场文书
质量整改报告范文
2014/11/08 职场文书
2015年世界无烟日活动总结
2015/02/10 职场文书
2016年清明节红领巾广播稿
2015/12/17 职场文书
Nginx代理同域名前后端分离项目的完整步骤
2021/03/31 Servers
JS一分钟在github+Jekyll的博客中添加访问量功能的实现
2021/04/03 Javascript
canvas多重阴影发光效果实现
2021/04/20 Javascript
详解PHP用mb_string处理windows中文字符
2021/05/26 PHP
Python+OpenCV实现在图像上绘制矩形
2022/03/21 Python
iSCSI服务器CHAP双向认证配置
2022/04/01 Servers