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中fade(),show()起始位置的一点小发现
Apr 25 jQuery
jQuery实现简单的滑动导航代码(移动端)
May 22 jQuery
bootstrap+jQuery实现的动态进度条功能示例
May 25 jQuery
jQuery用户头像裁剪插件cropbox.js使用详解
Jun 07 jQuery
jquery单击文字或图片内容放大并居中显示
Jun 23 jQuery
使用jquery的jsonp如何发起跨域请求及其原理详解
Aug 17 jQuery
jquery一键控制checkbox全选、反选或全不选
Oct 16 jQuery
jquery 获取索引值在一定范围的列表方法
Jan 25 jQuery
基于jquery实现左右上下移动效果
May 02 jQuery
jQuery时间戳和日期相互转换操作示例
Dec 07 jQuery
jQuery动态生成的元素绑定事件操作实例分析
May 04 jQuery
使用jQuery实现购物车
Oct 29 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 生成饼图 三维饼图
2009/09/28 PHP
php简单socket服务器客户端代码实例
2015/05/18 PHP
PHP实现的增强性mhash函数
2015/05/27 PHP
thinkPHP框架动态配置用法实例分析
2018/06/14 PHP
PHP大文件分片上传的实现方法
2018/10/28 PHP
jQuery 各种浏览器下获得日期区别
2008/12/22 Javascript
javascript URL锚点取值方法
2009/02/25 Javascript
extjs tabpanel限制选项卡数量实现思路及代码
2013/04/02 Javascript
JavaScript中有关一个数组中最大值和最小值及它们的下表的输出的解决办法
2016/07/01 Javascript
JS简单实现无缝滚动效果实例
2016/08/24 Javascript
浅谈js常用内置方法和对象
2016/09/24 Javascript
前端自动化开发之Node.js的环境搭建教程
2017/04/01 Javascript
详解Javascript中new()到底做了些什么?
2018/03/29 Javascript
Angular2中监听数据更新的方法
2018/08/31 Javascript
详解package.json版本号规则
2019/08/01 Javascript
vue-resource post数据时碰到Django csrf问题的解决
2020/03/13 Javascript
解决vue+router路由跳转不起作用的一项原因
2020/07/19 Javascript
JS画布动态实现黑客帝国背景效果
2020/11/08 Javascript
python基础教程之Hello World!
2014/08/29 Python
Python中方法链的使用方法
2016/02/23 Python
好的Python培训机构应该具备哪些条件
2018/05/23 Python
Django中间件基础用法详解
2019/07/18 Python
使用Keras实现Tensor的相乘和相加代码
2020/06/18 Python
python爬虫使用正则爬取网站的实现
2020/08/03 Python
python工具——Mimesis的简单使用教程
2021/01/16 Python
Staples加拿大官方网站:办公用品一站式采购
2016/09/25 全球购物
全球独特生活方式产品和礼品购物网站:AHAlife
2018/09/18 全球购物
北京鼎普科技股份有限公司软件测试面试题
2012/04/07 面试题
项目经理任命书
2014/06/04 职场文书
艺术设计专业毕业生推荐信
2014/07/08 职场文书
标准版离职证明书
2014/09/12 职场文书
经典导游欢迎词
2015/01/26 职场文书
2015年度服装销售工作总结
2015/03/31 职场文书
小学语文教学反思范文
2016/03/03 职场文书
go结构体嵌套的切片数组操作
2021/04/28 Golang
使用feign服务调用添加Header参数
2021/06/23 Java/Android