惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
S
SegmentFault 最新的问题
Engineering at Meta
Engineering at Meta
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Google DeepMind News
Google DeepMind News
博客园_首页
云风的 BLOG
云风的 BLOG
月光博客
月光博客
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Vercel News
Vercel News
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
P
Proofpoint News Feed
D
Docker
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
博客园 - 叶小钗
Martin Fowler
Martin Fowler
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - 刘杨兵

调用windows api(C#) 获得数据库中的所有表名和列名(C#) Excel编程[C#] 动态创建Access数据库文件(C#) NET Remoting简单介绍 程序集与COM组件 VS.NET新建项目失败(附解决方案) - 刘杨兵 - 博客园 XSLT C# DES加减密 下拉菜单 - 刘杨兵 - 博客园 类似软件风格的网页下拉菜单 datalist DOM 精简知识教程 DOM对象笔记(js) 自定义对话框 js中的位置[一] ASP.NET的缓存技术 httpModule[2] httpModule
js位置
刘杨兵 · 2006-12-12 · via 博客园 - 刘杨兵

scrollWidth
是对象的实际内容的宽,不包边线宽度,会随对象中内容的多少改变(内容多了可能会改变对象的实际宽度)

clientWidth
是对象可见的宽度,不包滚动条等边线,会随窗口的显示大小改变。

offsetWidth
是对象的可见宽度,包滚动条等边线,会随窗口的显示大小改变。


------------------------------------------------
一个scrollWidth和clientWidth的例子:
<html>
<head>
<title>77.htm文件</title>
</head>

<body>
<textarea wrap="off" onfocus="alert('scrollWidth:'+this.scrollWidth+'\n clientWidth:'+this.clientWidth);"></textarea>
</body>
</html>
在文本框内输入内容,当横向滚动条没出来前scrollWidth和clientWidth的值是一样的。
当一行内容超出文本框的宽度,就有横向滚动条出来了,scrollWidth的值就变了。
scrollWidth是对象实际内容的宽度。
clientWidth是对象看到的宽度(不含边线),这个例子里不会改变。


-----------------------------------------------
一个clientWidth和offsetWidth的例子:
<html>
<head>
<title>77.htm文件</title>
</head>

<body>
<textarea wrap="off" onfocus="alert('offsetWidth:'+this.offsetWidth+'\n clientWidth:'+this.clientWidth);"></textarea>
</body>
</html>

offsetWidth的值总是比clientWidth的值打
clientWidth是对象看到的宽度(不含边线)
offsetWidth是对象看到的宽度(含边线,如滚动条的占用的宽)

offsetLeft:Html元素相对于自己的offsetParent元素的位置

scrollLeft:返回和设置当前横向滚动务的坐标值

<input type="button" value="点一下" onclick="move()">
<div id="d" style="background-color:#ff9966; position:absolute; left:170px; top:100px;width:300;height:300;overflow:scroll"
onclick="alert('offsetLeft:'+this.offsetLeft)">
<div style="height:600;width:600" onclick="alert('offsetLeft:'+this.offsetLeft)"></div>
</div>
<script language="javascript">
function move()
{
var d=document.getElementById("d")
a=eval(20)
d.scrollLeft+=a
}
</script>

保存为网页,运行一下,点按钮,滚动条移动
点击div,先弹出b相对于a的位置,再弹出a相对于窗口的位置