JS 鼠标移动事件 mousemove

<style type="text/css">
*{
    margin:0px;
    padding:0px;
}
div{
    position:absolute;
}
</style>
<div style="width:200px;height:200px;color:white;background:#345678;font-size:20px;"></div>
<script type="text/javascript">
    //获取元素
    var div = document.getElementsByTagName('div')[0];

    window.onmousemove = function(e) {
        var x = e.clientX;
        var y = e.clientY;

        //修改
        div.innerHTML = 'x:'+x+'<br>y:'+y;

        //跟随移动
        div.style.left = x - 100 + 'px';
        div.style.top  = y - 100 + 'px';

        div.style.cursor = 'move';
    }
</script>