clientX, clientY是鼠标当前相对于网页的位置,当鼠标位于页面左上角时clientX=0, clientY=0;
offsetX, offsetY是鼠标当前相对于网页中的某一区域的位置,当鼠标位于页面中这一区域的左上角时offsetX=0, offsetY=0;
screenX, screenY是相对于用户显示器的位置
x,y是鼠标相对于当前浏览器的位置
x:设置或者是得到鼠标相对于目标事件的父元素的外边界在x坐标上的位置。
clientX:相对于客户区域的x坐标位置,不包括滚动条,就是正文区域。
offsetx:设置或者是得到鼠标相对于目标事件的父元素的内边界在x坐标上的位置。
screenX:相对于用户屏幕。
用window.document.body对象时
offsetWidth、offsetHeight IE工作区宽和高
clientWidth、clientHeight IE可见区宽和高
scrollWidth、scrollHeight IE水平滚动板宽度和垂直滚动板高度
screen.width、screen.height 屏幕的分辩率
left (x),top (y)是带单位的值
pixelLeft,pixelTop是不带单位的值
screen.availWidth, screen.availHeight是指除去TASKBAR以外的长宽,screen.availwidth和screen.availheight指的是系统屏幕工作区域的宽度和高度,不包括任务栏(Retrieves the width and height of the working area of the system's screen, excluding the Microsoft Windows taskbar. )
当你把任务栏设为自动隐藏时screen.availwidth和screen.availheight的值与screen.width和screen.height相同
获得控件在网页中的位置:
方法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+")")
}
jquery设置DIV层居中:
var scrollTop = document.body.scrollTop;//滚动条的高度jquery不知道怎么取,就用这种方法取好了
var height = ($(window).height - $("#id").height())/2+scrollTop;
$("#id").css("height", height );//DIV需要设置绝对定位