This article shares the specific code of JavaScript to realize the picture following the mouse movement for your reference. The specific content is as follows Implementation ideas 1. Bind the mousemove event to the document and get the mouse coordinates: e.pageX, e.pageY Tips: e.clientX - - Gets the mouse x-axis coordinate, relative to the browser window visible area ExampleCode example: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Get mouse coordinates</title> <style> img { /* width: 80px; height: 90px; */ position: absolute; } </style> </head> <body> <img src="images/斑.png" alt=""> <script> var img = document.querySelector('img'); document.addEventListener('mousemove', function(e) { var x = e.pageX; var y = e.pageY; img.style.top = y - 40 + 'px'; img.style.left = x - 48 + 'px'; }) </script> </body> </html> Page effect: The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Centos builds chrony time synchronization server process diagram
>>: Professional MySQL development design specifications and SQL writing specifications
Many friends who have just started to make web pag...
Building an image is a very important process in ...
Database application is an indispensable part of ...
Preface After MySQL version 3.23.44, InnoDB engin...
<br />Although there are many web page creat...
Table of contents Solution 1: Rebuild Replicas Pr...
Preface What is the role of an agent? - Multiple ...
Experimental environment A minimally installed Ce...
Table of contents 1. Several syntaxes of Insert 1...
First, let me briefly introduce what MySQL is; In...
I feel that the explanation of this.$set on the I...
Table of contents The principle of Vue asynchrono...
Table of contents 1. Background 2. Verification p...
Install TomCat on Windows This article will intro...
There are probably as many modular solutions for ...