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
Preface Now the operating system used by my compa...
This article example shares the specific code of ...
How to install PHP7 on Linux? 1. Install dependen...
Hyperlinks are the most frequently used HTML elem...
By default, MySQL in Linux distinguishes between ...
1. Link layout of the new site homepage 1. The loc...
Table of contents Preface 1. scp usage 2. Use sft...
This article example shares the specific code of ...
This article example shares the specific code of ...
Without further ado, let me show you the code. Th...
Table of contents 1. Introduction 2. Customize ta...
<template> <div id="root"> ...
This article example shares the specific code of ...
1. Rendering2. Operation steps 1. Apply for Tence...
The author has been working on a micro-frontend p...