03JavaScript程序设计修炼之道 2019-06-27_21-51-24 图片跟随
作者:互联网
18event-demo.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> img { width: 120px; height: 120px; border-radius: 50%; position: absolute; } </style> </head> <body> <img src="img/cxy.jpeg" alt=""> <script> var oImg = document.querySelector("img"); document.onmousemove = function(e) { var e = e || event; var x = e.pageX; var y = e.pageY; // 设置图片的坐标 oImg.style.left = (x-60) + "px"; oImg.style.top = (y-60) + "px"; } </script> </body> </html>
标签:24,oImg,style,27,06,img,px,60,var 来源: https://www.cnblogs.com/HiJackykun/p/11108902.html