Home > Web Front-end > JS Tutorial > body text

jquery enables pictures to follow mouse movement

小云云
Release: 2018-01-15 13:19:05
Original
2664 people have browsed it

I want to write a function that displays a QR code on the right side of a connection when the mouse moves, and follows the mouse movement. This article mainly introduces the relevant information about jquery's implementation of images following the mouse. I hope this article can help everyone realize such a function. , friends in need can refer to it, I hope it can help everyone.

Implementation code:


<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"){ 
        $(&#39;#1_erweima&#39;).hide(); 
      }else if(num.className == "2_name"){ 
        $(&#39;#2_erweima&#39;).hide(); 
      } 
    } 
 
    function showImg(num) { 
      var intX = window.event.clientX; 
      var intY = window.event.clientY; 
      if (num.className == "1_name") { 
        $(&#39;#1_erweima&#39;).css("left", intX + 20 + "px"); 
        $(&#39;#1_erweima&#39;).css("top", intY + 10 + "px"); 
        $(&#39;#1_erweima&#39;).show(); 
      } else if (num.className == "2_name") { 
        $(&#39;#2_erweima&#39;).css("left", intX + 20 + "px"); 
        $(&#39;#2_erweima&#39;).css("top", intY + 10 + "px"); 
        $(&#39;#2_erweima&#39;).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> 
  <p 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" /> 
  </p> 
  <p 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" /> 
  </p> 
</table> 
</body> 
</html>
Copy after login

Related recommendations:

jQuery implements the method of div following mouse movement Explain

Detailed example of using JS to implement cross coordinates following the mouse effect

Using JS to implement bubbles following the mouse movement animation special effect

The above is the detailed content of jquery enables pictures to follow mouse movement. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!