欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

event触发的坐标位置ev.clientx,ev.clienty

程序员文章站 2022-04-27 18:51:24
...
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>event</title>
    <style>
        #imgid{
            position: absolute;
            left: 0;
            top: 0;
            display: none;
        }
    </style>
</head>
<body>
<h1>aaaaaa</h1>
<h1>bbbbbb</h1>
<h1>cccccc</h1>
<h1>dddddd</h1>
<h1>eeeeee</h1>
<img src="wen.jpg" height="100px" width="100px" id="imgid" alt="">
</body>
</html>
<script>
    imgobj = document.getElementById('imgid');
    document.onmousemove = function (ev) {
        x = ev.clientX;
        y = ev.clientY;
        document.title = x+'-'+y;
        imgobj.style.left = x+'px';
        imgobj.style.top = y+'px';
        imgobj.style.display = 'inline';
    }
</script>