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"){ $('#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> <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>
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!