贴上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. ListCtrl 控件数据动态改动

    參考文章:ListCtrl 控件数据动态改动 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDIzNjU1MA==/font/5a6L5L2T/f ...

  2. HDU 4756 Install Air Conditioning(次小生成树)

    题目大意:给你n个点然后让你求出去掉一条边之后所形成的最小生成树. 比較基础的次小生成树吧. ..先prime一遍求出最小生成树.在dfs求出次小生成树. Install Air Conditioni ...

  3. [Python]Use Flask-Admin with PostgreSQL

    This code recipe gives you an idea of how to use Flask-Admin with postgresql database. from flask im ...

  4. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第1章节--SharePoint 2013 介绍 处理开发者需求

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第1章节--SharePoint 2013 介绍 处理开发者需求         SharePoint本质上是一个平台.你 ...

  5. Linux平台不同解压缩命令的使用方法

    作者:郭孝星 微博:郭孝星的新浪微博 邮箱:allenwells@163.com 博客:http://blog.csdn.net/allenwells github:https://github.co ...

  6. 部署zookeeper实践

    1.解压zookeeper 2.环境变量设置 hadoop@namenode:~/zookeeper-3.4.6/conf$ sudo vim /etc/profile export JAVA_HOM ...

  7. Eclipse中项目进行发布到Tomcat中的位置

    Eclips配置tomcat默认是发布到.metadate\plugins\目录下的,wtpwebapps.这样在实际的tomcat目录下,就找不到发布的项目.我们可以自己进行设置,在控制栏中找到se ...

  8. Java (JDK7)中的String常量和String.intern的实现

    在java中有constantPool常量池,常量池里存放的是类,方法,接口的等常量,而对于存放字符串常量通常存放的符号链接Symbol 或者真实的String的对象的引用. 我们来看一段简单的代码和 ...

  9. less02-变量

    html <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF- ...

  10. hdoj--5256--序列变换(lis变形)

    序列变换 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...