DOM中的位置和大小(总结)

【window】window对象

一、position位置
screenLeft/screenTop (适用于火狐和谷歌)
screenX/screenY (适用于IE)

二、size大小

innerHeight/innerWidth 显示文档的区域大小
outerHeight/outerWidth 这个窗口大小包括工具栏、滚动条

【element】元素对象

一、position位置

offsetLeft / offsetTop 边框盒的位置,一第一个定位(position:absolute)的父级元素为准

二、size大小

clientWidth/clientHeight 内容+内边距(填充盒)
offsetWidth/offsetHeight 内容+内边距+边框(边框盒)

【mouse】鼠标事件对象

clientX/clientY 相对于视口的坐标
pageX/pageY 相对于事件源的位置
offsetX/offsetY 相对于整个文档的位置
screenX/screenY 相对于屏幕的位置

猜你喜欢

转载自www.cnblogs.com/yuanjunjundebo/p/12008531.html