JS获取各种宽度、高度 【scrollWidth clientWidth offsetWidth】
来源:互联网 发布:excel数据统计软件 编辑:程序博客网 时间:2024/06/05 00:14
scrollWidth clientWidth offsetWidth的关系。
JS获取各种宽度、高度的简单介绍:
scrollHeight: 获取对象的滚动高度。 scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离 scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离 scrollWidth:获取对象的滚动宽度 offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度 offsetLeft:获取对象相对于版面或由 offsetParent 属性指定的父坐标的计算左侧位置 offsetTop:获取对象相对于版面或由 offsetTop 属性指定的父坐标的计算顶端位置 event.clientX 相对文档的水平座标 event.clientY 相对文档的垂直座标 event.offsetX 相对容器的水平坐标 event.offsetY 相对容器的垂直坐标 document.documentElement.scrollTop 垂直方向滚动的值 event.clientX+document.documentElement.scrollTop 相对文档的水平座标+垂直方向滚动的量
以上主要指IE之中,FireFox差异如下:
IE6.0、FF1.06+:
clientWidth = width + padding clientHeight = height + padding offsetWidth = width + padding + border offsetHeight = height + padding + border
IE5.0/5.5:
clientWidth = width - border clientHeight = height - border offsetWidth = width offsetHeight = height
CSS中的margin属性,与clientWidth、offsetWidth、clientHeight、offsetHeight均无关
offsetWidth (width+padding+border)
假设 obj 为某个 HTML 控件。
obj.offsetTop 指 obj 距离上方或上层控件的位置,整型,单位像素。
obj.offsetLeft 指 obj 距离左方或上层控件的位置,整型,单位像素。
obj.offsetWidth 指 obj 控件自身的宽度,整型,单位像素。获取对象可见内容的宽度,不包括滚动条,不包括边框;
obj.offsetHeight 指 obj 控件自身的高度,整型,单位像素。
offsetWidth 与 style.width 的区别
一、offsetTop 返回的是数字,而 style.top 返回的是字符串,除了数字外还带有单位:px。
二、offsetTop 只读,而 style.top 可读写。
三、如果没有给 HTML 元素指定过 top 样式,则 style.top 返回的是空字符串。
0 0
- JS获取各种宽度、高度 【scrollWidth clientWidth offsetWidth】
- js scrollLeft,scrollWidth,clientWidth,offsetWidth
- JS 获取浏览器窗口大小clientWidth、offsetWidth、scrollWidth
- JS 获取浏览器窗口大小clientWidth、offsetWidth、scrollWidth
- 各种width,offsetWidth, getBoundingClientRect(), clientWidth,scrollWidth区别
- js:scrollLeft,scrollWidth,clientWidth,offsetWidth完全详解
- js:scrollLeft,scrollWidth,clientWidth,offsetWidth完全详解
- js:scrollLeft,scrollWidth,clientWidth,offsetWidth完全详解
- js:scrollLeft,scrollWidth,clientWidth,offsetWidth完全详解
- JS中关于clientWidth、offsetWidth、scrollWidth
- js获取宽度 ,各种高度宽度document.body.clientWidth , document.body.clientHeight,window.screen.width 等等
- js获取宽度 ,各种高度宽度document.body.clientWidth , document.body.clientHeight,window.screen.width 等等
- scrollLeft,scrollWidth,clientWidth,offsetWidth
- scrollLeft,scrollWidth,clientWidth,offsetWidth
- scrollLeft,scrollWidth,clientWidth,offsetWidth
- offsetWidth、clientWidth、scrollWidth、scrollTop
- offsetWidth、clientWidth、scrollWidth、scrollTop
- scrollWidth,clientWidth,offsetWidth 区别
- php图片上传之图片转换
- 左旋转字符串
- 简单介绍及安装Linq To Object的扩展类库MoreLinq
- unimplemented or unreasonable conversion requested
- 约束
- JS获取各种宽度、高度 【scrollWidth clientWidth offsetWidth】
- 让Qt应用程序跑在Android上
- #define和typedef的用法与区别及面试问题
- java 反射的理解
- RMAN备份与恢复(1)对数据库进行完全介质恢复
- MVC自带异步请求
- FIFO、LFU、LRU三种缓存策略之间的区别
- la 4513 Stammering Aliens 字符串哈希
- CentOS开启daytime服务器