现在有一个需求,就是取html中某个元素的坐标值,有如下代码:function getPosition(theElement){
var positionX =0;
var positionY =0;
while (theElement !=null){
positionX +=theElement.offsetLeft;
positionY +=theElement.offsetTop;
theElement =theElement.offsetParent;
}
alert(positionX);
alert(positionY);
}该方法可以取道X,Y值,但是对于各个不同尺寸的显示器所取道的值就不一样,例如我是19的显示器取的X值是200,但在14寸的显示器下同一个元素的X坐标却是50,请教大家有没有其他的方法,让在各个尺寸的显示器下取的X,Y的值都一样?
var positionX =0;
var positionY =0;
while (theElement !=null){
positionX +=theElement.offsetLeft;
positionY +=theElement.offsetTop;
theElement =theElement.offsetParent;
}
alert(positionX);
alert(positionY);
}该方法可以取道X,Y值,但是对于各个不同尺寸的显示器所取道的值就不一样,例如我是19的显示器取的X值是200,但在14寸的显示器下同一个元素的X坐标却是50,请教大家有没有其他的方法,让在各个尺寸的显示器下取的X,Y的值都一样?
你页面上的position都是absolute的.不然会根据用户的客户端拉伸的.