坐标如何拿到 ?

解决方案 »

  1.   


    var oDiv = document.getElementById("div1");
     iDiffX = event.clientX - oDiv.offsetLeft; //得到X
     iDiffY = event.clientY - oDiv.offsetTop;  //得到Y
      

  2.   

    document.oncontextmenu = function(evt){
    evt = evt || window.event;
    e0 = document.getElementById('RBmenu');
    e0.style.top = evt.clientY;
    e0.style.left = evt.clientX;
    e0.style.display = "inline";
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title></title>
        <style type="text/css">
            html, body { margin:0; padding:0;height:100%}
        </style>
    </head>
    <body onload="s()" onresize="s()">
    <div style="width:100px; height:100px; background:red; position:absolute;" id="s">
    fdsaf
    </div>
    <script>
        function s() {
            document.getElementById("s").style.top = (document.body.clientHeight/2) - (parseInt(document.getElementById("s").style.height) / 2) + "px";
            document.getElementById("s").style.left = (document.body.clientWidth/2) - (parseInt(document.getElementById("s").style.width) / 2) + "px";
        }
    </script>
    </body>
    </html>
      

  4.   

    正常我们打开了一个网页最大化,的时候我们可以让一个div显示在屏幕的最中央。位置呢就是
    横向是
    div.style.left=(document.body.clientWidth-div.style.width)/2div.style.top=
    (document.body.clientHeight-div.styhle.height)/2当进行滚动的时候比如横向的滚动条:
    div.style.left+=document.body.scrollLeft
    当进行纵向滚动时:
    div.style.top+=document.body.scrollTop;