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=" 80px;height: 50px;position:absolute"></div>
</body>
</html>

原文地址:https://www.cnblogs.com/Dionexin/p/5954478.html