1.js获取对象的绝对坐标 方法1:

function   getAbsPoint(e)  
{  
    var   x   =   e.offsetLeft,   y   =   e.offsetTop;  
    while(e=e.offsetParent)
    {
       x   +=   e.offsetLeft;  
       y   +=   e.offsetTop;
    }
    alert("x:"+x+","+"y:"+y);  
}

 

方法2:

function   getAbsPoint(obj)  
{  
  var   x,y;  
  oRect   =   obj.getBoundingClientRect();  
  x=oRect.left;
  y=oRect.top; 
  alert("("+x+","+y+")")  
}

 

JS中获得窗口属性的方法
1。获得屏幕的分辨率:

screen.width
screen.height

2。获得窗口大小:

document.body.clientWidth
document.body.clientHeight

3。获得窗口大小(包含Border、Scroll等元素)

document.body.offsetWidth
document.body.offsetHeight 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script>
        function getScreen(e) {
            var x = e.screenX - e.clientX;
            var y = e.screenY - e.clientY;
            alert("X坐标:" + x + ",Y坐标:" + y);
        }
    </script>
</head>
<body>
    <input type="button" onclick="getScreen(event)" value="测试" />
</body>
</html>

 

相关文章:

  • 2021-07-14
  • 2022-12-23
  • 2021-11-07
  • 2021-11-07
  • 2021-09-08
  • 2022-12-23
  • 2021-11-07
  • 2021-11-07
猜你喜欢
  • 2021-08-31
  • 2021-11-07
  • 2021-11-07
  • 2021-11-07
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案