div随着鼠标的移动而移动

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function getXy1(event) {
            var flow = document.getElementById("flow");
            flow.style.left = event.clientX  + 5 +"px";
            flow.style.top  = event.clientY  + 5 + "px";
            flow.innerHTML="<h6>"+event.clientX+":"+event.clientY+"</h6>";
        }
    </script>
</head>
//注意这里用的方法  onmousemove;body里边设置了一个样式

<body onmousemove="getXy1(event)"style="height: 1000px">
<div id="flow" style="width: 80px;height: 50px;position:absolute"></div>
</body>
</html>

posted @ 2016-10-12 21:31  Dione_xin  阅读(1378)  评论(0编辑  收藏  举报