快捷搜索:   MySQL PHP linux 播放器

JS 监测鼠标移动方向

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body style="width: 100%;height: 100vh;" onmousemove="getMovePosit(event)" onmousedown="getNowMove(event)">
        <span id="ospan"></span>
    </body>
    <script language="JavaScript">
        var oldY,oldX;
        function getNowMove(event){
            oldY = event.clientY, oldX = event.clientX;
            console.log(oldY,oldX);
        }
        function getMovePosit(event) {
            if (oldY == event.clientY) {
                document.all.ospan.innerText = "鼠标没有动静了?"
            }
            if (oldY > event.clientY) {
                document.all.ospan.innerText = "鼠标向上移了"
            }
            if (oldY < event.clientY) {
                document.all.ospan.innerText = "鼠标向下移了"
            }
            if (oldX > event.clientX) {
                document.all.ospan.innerText = "鼠标向左移了"
            }
            if (oldX < event.clientX) {
                document.all.ospan.innerText = "鼠标向右移了"
            }
            oldY = event.clientY, oldX = event.clientX;
            console.log('error');
        }
    </script>
</html>



您可能还会对下面的文章感兴趣:

头像:

设置头像

x
名称(*):
域名    :
邮箱    :

评论内容(*): 刷新评论 提交评论