<!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>Document</title> <link rel="stylesheet" href="style.css"> </head> <body> <img src="img/angel .gif" alt="天使"> <script src="style.js"></script> </body> </html> var img = document.querySelector('img'); document.addEventListener('mousemove',function(e){ var x = e.pageX; var y = e.pageY; img.style.left = x-50+'px'; img.style.top = y-40+'px'; }); *{ margin:0; padding:0; } img{ position: absolute; }