贴上MDN对scrollwidth的定义:

The Element.scrollWidth read-only property is a measurement of the width of an element's content, including content not visible on the screen due to overflow.

自译:element.scrollWidth这个只读属性是用来测量元素内容宽度的一种方式,它包括了被overflow属性隐藏的不可见的宽度.

The scrollWidth value is equal to the minimum width the element would require in order to fit all the content in the viewport without using a horizontal scrollbar. The width is measured in the same way as clientWidth: it includes the element's padding, but not its border, margin or vertical scrollbar (if present). It can also include the width of pseudo-elements such as ::before or ::after. If the element's content can fit without a need for horizontal scrollbar, its scrollWidth is equal to clientWidth.

自译:scrollWidth值等于元素的最小宽度要求内容与视口相适,不使用水平的滚动条(意思应该就元素内容不要太大导致水平滚动条出现吧).这个宽度的测量方式与clientWidth方式一样,包括元素的内边距,不包括边框,外边距,垂直滚动条(如果有出现的话).它也可以包括包括伪元素的宽度例如::before或::after.如果元素的内容刚好合适不需要水平滚动条,那么scrollwidth就等于clientWdth.

看的似懂非懂,直接代码测试:

html部分略
<script>
var box = document.getElementById("box");
// 页面可视区的宽度
var oClientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0; // 页面可视区的高度
var oClientHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0; // scrollTop 网页被卷起的高度
var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; // scrollLeft 网页左边被卷起的宽度
var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0; // scrollWidth 表示整个网页正文的宽度
var scrollWidth = document.documentElement.scrollWidth || document.body.scrollWidth; // scrollHeight 表示整个网页正文的高度
var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight; box.onclick = function(e){
var oEvent = e || event;
console.log('相对显示器左边的位置screenX为:' + oEvent.screenX); //95
console.log('相对显示器上边的位置screenY为:' + oEvent.screenY); //152
console.log('相对可视区左边的位置clientX为:' + oEvent.clientX); //95
console.log('相对可视区上边的位置clientY为:' + oEvent.clientY); //61
console.log('可视区宽度clientWidth为:' + oClientWidth); //1920
console.log('可视区高度clientHeight为:' + oClientHeight); //535
console.log('点击位置在页面中的纵坐标为:' + (oEvent.clientY + scrollTop)); //1461
console.log('点击位置在页面中的横坐标为:' + (scrollLeft + oEvent.clientX)); //95
console.log('页面卷起的高度scrollTop为:' + scrollTop); //1400
console.log('页面左边卷起的宽度为scrollLeft为:' + scrollLeft); //0
alert('盒子的宽度为scrollWideth为:' + box.scrollWidth); //3000
alert('页面的宽度为scrollWideth为:' + scrollWidth);
console.log('页面的高度为scrollHeight为:' + scrollHeight); //5000
console.log('点击位置相对页面位置的左边pageX为:' + oEvent.pageX); //95
console.log('点击位置相对页面位置的上边pageY为:' + oEvent.pageY); //1461
//1461
}
</script>

1.盒子大小<body大小<浏览器窗口大小

a)        当body/html调用scrollwidth:

chrome, ie6-ie11:

body.scrollWidth=浏览器可视窗口宽度(clientWidth)--滚动条栏的宽度

b)        当盒子调用:

chrome, ie6-ie11:

box.scrollwidth=width+padding

2.盒子大小<浏览器窗口大小< body大小

a)        body/html调用scrollwidth:

chrome, ie6-ie11:

body.scrollWidth=body.width+ body.padding+ body.border+左边的margin

(只对body的值进行累计,如果box有margin撑大了body也把box.margin的宽度不会计算进来)

b)        当盒子调用:

chrome, ie6-ie11:

box.scrollwidth=width+padding;

3.浏览器窗口大小<盒子大小< body大小

同情况2

4.body大小<盒子大小<浏览器窗口大小

chrome,ie11:

body.scrollWidth=浏览器可视窗口宽度--滚动条栏的宽度

box.scrollwidth=width+padding;

5.body大小<浏览器窗口大小<盒子大小

chrome,ie11:

body.scrollWidth=body.width+ body padding+ body.margin+body.leftpadding+body.leftboder+body.leftmargin;

box.scrollWidth=width+padding;

6.浏览器窗口大小 < body大小 <盒子大小

chrome,ie11:

body.scrollWidth= box.width+ box.padding+ box.margin+body.leftpadding+body.leftboder+body.leftmargin;

box.scrollWidth=box.width+box.padding;

总结:

看了很多资料说是clientWidth是可视区域大小其实也是包括了滚动条栏的宽度.

不管啥情况:box.scrollWidth=box.width+box.padding;

如果浏览器的窗口宽度最大:

body.scrollWidth=浏览器窗口大小(clientWidth)-右侧滚动条栏宽度(一般是17px);

如果是body的宽度(border+padding)最大:

body.scrollWidth=body.width+ body.padding+ body.border+左边的margin;

如果是盒子的宽度(border+padding)最大:

body.scrollWidth= box.width+ box.padding+ box.margin+body.leftpadding+body.leftboder+body.leftmargin;

scrollWidth到底是什么???的更多相关文章

  1. HTML:scrollLeft,scrollWidth,clientWidth,offsetWidth到底指的哪到哪的距离之完全详解

    scrollHeight: 获取对象的滚动高度. scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离 scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最 ...

  2. HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解

    HTML:scrollLeft,scrollWidth,clientWidth,offsetWidth到底指的哪到哪的距离之完全详解 scrollHeight: 获取对象的滚动高度. scrollLe ...

  3. scrollWidth,offsetWidth,clientWidth,width;scrollHeight,offsetHeight,clientHeight,height;offsetTop,scrollTop,top;offsetLeft,scrollLeft,left还有谁

    题中的那么多属性让人头都大了,他们到底是什么意思?不同浏览器的实现是一样的吗?以下所有结论来自chrome版本 53.0.2785.89 (64-bit)和firefox版本52.0.2,操作系统ub ...

  4. H5,PC网页屏幕尺寸相关整理(scrollLeft,scrollWidth,clientWidth,offsetWidth)

    HTML:scrollLeft,scrollWidth,clientWidth,offsetWidth到底指的哪到哪的距离之完全详解scrollHeight: 获取对象的滚动高度. scrollLef ...

  5. 转 HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解

    HTML:scrollLeft,scrollWidth,clientWidth,offsetWidth到底指的哪到哪的距离之完全详解 scrollHeight: 获取对象的滚动高度. scrollLe ...

  6. 拨开迷雾,找回自我:DDD 应对具体业务场景,Domain Model 到底如何设计?

    写在前面 除了博文内容之外,和 netfocus 兄的讨论,也可以让你学到很多(至少我是这样),不要错过哦. 阅读目录: 迷雾森林 找回自我 开源地址 后记 毫无疑问,领域驱动设计的核心是领域模型,领 ...

  7. Js new到底发生了什么

    在Js中,我们使用了new关键字来进行实例化 那么在这个new的过程中到底发生了什么? 关于构造函数的return 正常来讲构造函数中是不用写return语句的,因为它会默认返回新创建的对象. 但是, ...

  8. 电信计费业务:预后融合OCS到底应该实扣还是虚扣?

    引入OCS的初衷之一是为了让计费系统能够参与到用户的通讯控制中来,也就是所谓的实时信控.用户在没有余额时,通讯就会被停止,不会造成"天价欠费 ",一方面保障用户的利益,一方面也保障 ...

  9. 港真,到底应该选择OA还是BPM?

    越来越多企业意识到流程管理的重要性,但是,选择OA还是BPM,却让他们产生了选择困难症. 一方面,企业皆注重流程的高效运转,最好内外部的业务都能用一个系统来解决.所有流程一天就能上线什么的,那就更好啦 ...

随机推荐

  1. 通过案例快速学会Picasso图片缓存库

    picasso是Square公司开源的一个Android图形缓存库,官网地址http://square.github.io/picasso/,可以实现图片下载和缓存功能.        下载地址:ht ...

  2. Android Camera子系统之Linux C应用开发人员View

    Android Camera HAL通过V4L2接口与内核Camera Driver交互.本文从Linux应用开发人员的角度审视Android Camera子系统. V4L2应用开发一般流程: 1. ...

  3. 【剑指Offer面试题】 九度OJ1371:最小的K个数

    题目链接地址: http://ac.jobdu.com/problem.php?pid=1371 题目1371:最小的K个数 时间限制:1 秒内存限制:32 兆特殊判题:否提交:5938解决:1265 ...

  4. java根据模板导出PDF(利用itext)

    一.制作模板     1.下载Adobe Acrobat 9 Pro软件(pdf编辑器),制作模板必须使用该工具. 2.下载itextpdf-5.5.5.jar.itext-asian-5.2.0.j ...

  5. Spring深入浅出(四)AOP面向切面

    面向切面编程--AOP AOP(Aspect Oriented Programming),程序员称之为面向切面编程,是Spring框架除了IOC之外的另一个核心概念. AOP是对OOP(面向对象编程) ...

  6. animation和transition做动画的区别

    animation做动画,是不需要去触发的,可以定义一开始就执行 transition做动画,是需要人为触发,才能执行的

  7. theano import error (win10 python2.7)

    因为项目需要,在win10-64位电脑上配置theano.但是一直有 import error的错误,找不到解决方法.作为一个python新手,实在搞不定,请大家不吝赐教!小女子不胜感激! 按照网上的 ...

  8. Windows 10 计划带来颜文字和Sandbox

    在最新的 Window 10 测试版 Build 18305 中,Windows 10 增加了对颜文字(kaomoji)的支持. Kaomoji 是由日本符号序列组成的面脸部表情的名称.虽然有些人,比 ...

  9. 13-Linux中进程与线程的概念以及区别

    linux进程与线程的区别,早已成为IT界经常讨论但热度不减的话题.无论你是初级程序员,还是资深专家,都应该考虑过这个问题,只是层次角度不同罢了.对于一般的程序员,搞清楚二者的概念并在工作中学会运用是 ...

  10. 20180929 北京大学 人工智能实践:Tensorflow笔记04

    20180929 北京大学 人工智能实践:Tensorflow笔记03(2018-09-30 00:01)