网页元素位置(scroll、client、offsetWidth等)获取、设置详解

时间:2024-04-08 21:39:12

网页元素位置(scroll、client、offsetWidth等)获取、设置详解

说明
scrollHeight: 获取对象的滚动高度,也就是如果不带滚条动时,完全伸展时的高度。
scrollLeft:
设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离
scrollTop:
设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离
scrollWidth:
获取对象的滚动宽度,也就是如果不带滚条动时,完全伸展时的宽度。
offsetHeight:
获取对象相对于版面或由父坐标offsetParent 属性指定的父坐标的高度
offsetLeft:
获取对象相对于版面或由 offsetParent 属性指定的父坐标的计算左侧位置
offsetTop:
获取对象相对于版面或由 offsetParent 属性指定的父坐标的计算顶端位置
offsetWidth:
获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的宽度
---------------------------------------------------------
具体请看示例: (可以改变文本框的行数或拉到滚动条看数值变化)
---------------------------------------------------------

welcome to: http://www.easewe.com 欢迎访问亿思维空间 http://www.easewe.com welcome to: http://www.easewe.com 欢迎访问亿思维空间 http://www.easewe.com welcome to: http://www.easewe.com 欢迎访问亿思维空间 http://www.easewe.com welcome to: http://www.easewe.com 欢迎访问亿思维空间 http://www.easewe.com welcome to:http://www.easewe.com 欢迎访问亿思维空间:http://www.easewe.com

txtEaseWe.offsetHeight=100
txtEaseWe.clientHeight=81
txtEaseWe.scrollHeight=446

txtEaseWe.offsetLeft=230
txtEaseWe.clientLeft=1
txtEaseWe.scrollLeft=0

txtEaseWe.offsetTop=856
txtEaseWe.clientTop=1
txtEaseWe.scrollTop=365

txtEaseWe.offsetWidth=300
txtEaseWe.clientWidth=281
txtEaseWe.scrollWidth=281

txtEaseWe.offsetParent=[object]