天天看点

Js中实现图片随鼠标移动——ClientX,ClientY,Position

<head>

    <script type="text/javascript">

        // 当监听事件受到body范围大小的限制的时候,那么就在document中监听

        document.onmousemove = function () {

           //获得鼠标的坐标值

           var x = window.event.clientx;

           var y = window.event.clienty;

            var divfly = document.getelementbyid("divfly");

            divfly.style.left = x;

            divfly.style.top = y;

        }

    </script>

</head>

<body>

    <div id="divfly" style="position:absolute">

        <img src="../images/b6.gif" alt="positiondemo" />

    </div>

</body>

继续阅读