区分scrollWidth, clientWidth, offsetWidth 与scrollLeft
2015-03-02 15:56
399 查看
1. scrollWidth, clientWidth 与offsetWidth
scrollWidth 是对象的实际内容的宽,不包边线宽度,会随对象中内容的多少改变(内容多了可能会改变对象的实际宽度)。
clientWidth 是对象可见的宽度,不包滚动条等边线,会随窗口的显示大小改变。
offsetWidth 是对象的可见宽度,包滚动条等边线,会随窗口的显示大小改变。
实例:
执行结果(FF):
offsetWidth的值总是比clientWidth的值大。
clientWidth是对象看到的宽度(不含边线)
offsetWidth是对象看到的宽度(含边线,如滚动条的占用的宽)
在文本框内输入内容,当横向滚动条没出来前scrollWidth和clientWidth的值是一样的。
当一行内容超出文本框的宽度,就有横向滚动条出来了,scrollWidth的值就变了。
scrollWidth是对象实际内容的宽度。
clientWidth是对象看到的宽度(不含边线),这个例子里不会改变。
2. scrollWidth与scrollLeft
obj.scrollWidth 指 obj 控件实际内容的宽度,包括因 overflow 而未显示的部分,也就是其实际占据的宽度,整型,单位像素。 scrollLeft就是指横向滚动条滚动后,左边不可见的那部分的宽度。
两个值:scrollTop, scrollLeft
第一个代表页面利用滚动条滚动到下方时,隐藏在滚动条上方的页面的高度;
第二个代表页面利用滚动条滚动到右侧时,隐藏在滚动条左侧的页面的宽度。
scrollWidth 是对象的实际内容的宽,不包边线宽度,会随对象中内容的多少改变(内容多了可能会改变对象的实际宽度)。
clientWidth 是对象可见的宽度,不包滚动条等边线,会随窗口的显示大小改变。
offsetWidth 是对象的可见宽度,包滚动条等边线,会随窗口的显示大小改变。
实例:
执行结果(FF):
offsetWidth的值总是比clientWidth的值大。
clientWidth是对象看到的宽度(不含边线)
offsetWidth是对象看到的宽度(含边线,如滚动条的占用的宽)
在文本框内输入内容,当横向滚动条没出来前scrollWidth和clientWidth的值是一样的。
当一行内容超出文本框的宽度,就有横向滚动条出来了,scrollWidth的值就变了。
scrollWidth是对象实际内容的宽度。
clientWidth是对象看到的宽度(不含边线),这个例子里不会改变。
2. scrollWidth与scrollLeft
obj.scrollWidth 指 obj 控件实际内容的宽度,包括因 overflow 而未显示的部分,也就是其实际占据的宽度,整型,单位像素。 scrollLeft就是指横向滚动条滚动后,左边不可见的那部分的宽度。
两个值:scrollTop, scrollLeft
第一个代表页面利用滚动条滚动到下方时,隐藏在滚动条上方的页面的高度;
第二个代表页面利用滚动条滚动到右侧时,隐藏在滚动条左侧的页面的宽度。
相关文章推荐
- JS 盒模型 scrollLeft, scrollWidth, clientWidth, offsetWidth 详解
- scrollLeft,scrollWidth,clientWidth,offsetWidth到底指的哪到哪的距离之完全详解
- scrollLeft,scrollWidth,clientWidth,offsetWidth到底指的哪到哪的距离
- javascript scrollLeft,scrollWidth,clientWidth,offsetWidth 完全详解
- scrollLeft,scrollWidth,clientWidth,offsetWidth到底指的哪到哪的距离
- offsetTop、offsetLeft、offsetWidth、offsetHeight,scrollTop、scrollLeft、scrollWidth、scrollHeight ,clientHeight、offsetHeight
- offsetWidth、offsetLeft、clientWidth、clientLeft、scrollWidth、scrollLeft各自特点比较
- JS:body元素对象的clientWidth、offsetWidth、scrollWidth、clientLeft、offsetLeft、scrollLeft
- scrollLeft,scrollWidth,clientWidth,offsetWidth到底指的哪到哪的距离
- JS:document.documentElement对象的clientWidth、offsetWidth、scrollWidth、clientLeft、offsetLeft、scrollLeft
- JS:body元素对象的clientWidth、offsetWidth、scrollWidth、clientLeft、offsetLeft、scrollLeft
- js控制的DIV一些属性 scrollLeft,scrollWidth,clientWidth,offsetWidth .
- scrollLeft,scrollWidth,clientWidth,offsetWidth到底指的哪到哪的距离之完全详解
- scrollLeft,scrollWidth,clientWidth,offsetWidth,event用法及说明
- 图示offsetWidth、clientWidth、scrollWidth、scrollTop、scrollLeft等属性
- 完全图解scrollLeft,scrollWidth,clientWidth,offsetWidth 获取相对途径,滚动图片(网上找的,未经试验,但觉得比较好)
- clientWidth、offsetWidth、scrollWidth、clientLeft、offsetLeft、scrollLeft的测试Dome
- clientWidth、offsetWidth、scrollWidth、clientLeft、offsetLeft、scrollLeft的测试Dome
- 深刻了解offsetTop,offsetLeft,offsetWidth,offsetHeight,scrollTop,scrollLeft,scrollWidth,scrollHeight,clientHeight,clientWidth
- Web前端之 offsetWidth,clientWidth,scrollWidth,offsetLeft,clientLeft,scrollLeft