其他分享
首页 > 其他分享> > js实时显示鼠标坐标

js实时显示鼠标坐标

作者:互联网

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>鼠标坐标随时变动</title>
</head>
<body>
<div id="event"></div>
<script type="text/javascript">
    var id = document.getElementById('event');
    document.addEventListener('mousemove',function(e){
        id.style.marginLeft = e.clientX + 'px';
        id.style.marginTop = e.clientY + 'px';
        id.innerHTML = "(X:" + e.clientX+",Y:"+e.clientY+ ")";
    });
</script>
</body>
</html>

标签:clientX,clientY,style,鼠标,px,js,坐标,document,id
来源: https://www.cnblogs.com/mike2001/p/10767044.html