鼠标移动特效之图片跟随鼠标移动

代码如下:

<!DOCTYPE html>
<html>

<head>
    <title></title>
    <meta charset="utf-8">
    <style type="text/css">
        #im {
            position: absolute;
            width: 66px;
        }
    </style>
</head>

<body>
    <img src="timg.gif" id="im" alt="" />
    <script type="text/javascript">
        var imobj = document.getElementById("im");
        document.onmousemove = function (e) {
            imobj.style.left = e.clientX + 25 + "px";
            imobj.style.top = e.clientY + "px";
        }
    </script>
</body>

</html>

效果演示:https://fifteen718.github.io/

猜你喜欢

转载自blog.csdn.net/fifteen718/article/details/82907651