zoukankan      html  css  js  c++  java
  • jquery中clientY,pageY和screenY的区别 最后三张图一目了然。

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>jquery获取坐标</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <link href="" rel="stylesheet">
    <style>
        * {margin: 0;padding: 0;}
        div p {
            display: inline-block;box-sizing: border-box;
        }
    </style>
    </head>
    <body style="height:1200px;">
    <div style="100%;position: fixed;top: 0;background: #000;color: white;padding: 2px 20px;">
    <p>鼠标当前的屏幕坐标是:<span class="showCoordinate">x:0,y:0</span></p>
    <p>鼠标当前窗口客户区的坐标是:<span class="showCusCoord">x2:0,y2:0</span></p>
    <p>鼠标在窗口页面中的坐标是:<span class="showPageCoord">x3:0,y3:0</span></p>
    </div>
        <script src="../jquery1.js"></script>
        <script>
        $(document).ready(function(){
            $(document).mousemove(function(e){
                //获取鼠标在屏幕上的坐标
                x=e.screenX;//屏幕的左上角为参考点
                y=e.screenY;//获取屏幕的x和y坐标
                $(".showCoordinate").text("screenX:"+x+",screenY:"+y);
                //获取鼠标在当前窗口区域中的坐标
                x2=e.clientX;
                y2=e.clientY;
                $(".showCusCoord").text("clientX:"+x2+",clientY:"+y2);
                //返回事件被触发时鼠标指针相对于文档左边缘的位置
                x3=e.pageX;
                y3=e.pageY;(会随着滚动条的变化而变化)
                $(".showPageCoord").text("pageX:"+x3+",pageY:"+y3);
                
            });
        });    
        </script>
    </body>
    </html>


    screenX,screenY是距离屏幕边缘的距离

    clientX,clientY是距离当前可是窗口的距离

    pageX,pageY是相对于当前页面中的坐标(会随着滚动条的滚动而变化)

  • 相关阅读:
    算法笔记--二分图判定
    算法笔记--最小表示法
    Codeforces 525A
    Codeforces 140D
    Codeforces C
    Codeforces 665C
    Codeforces 604B
    Codeforces 285C
    The Fewest Coins POJ
    Triangular Pastures POJ
  • 原文地址:https://www.cnblogs.com/gluncle/p/8073918.html
Copyright © 2011-2022 走看看