JS small practice --- mouse follow (with comments)

<!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>
    <style>
        img{
            width: 30px; 
            position:relative;
            top:10px  ;
            left: 10px ;
        }
    </style>
</head>
<body>
    <img src="../8.19/img/eyes.png" alt="">
    <script>
        img=document.querySelector("img")
        document.addEventListener("mousemove",function(e){
            let x=e.pageX-22 +"px"
            let y=e.pageY-22 +"px"
            console.log(x,y);
            // img.className=".mousemove"
            img.style.top=y
            img.style.left=x

        })
    </script>
</body>
</html>

Guess you like

Origin blog.csdn.net/m0_45293340/article/details/126479733