scrollLeft,scrollWidth,clientWidth,offsetWidth

scrollLeft,scrollWidth,clientWidth,offsetWidthhttp://wenku.baidu.com/view/c1250d46b307e87101f6960d.htmlHTML:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解(转)————————————————vars=””;s+=”网页可见区域宽

大家好,又见面了,我是你们的朋友全栈君。

http://wenku.baidu.com/view/c1250d46b307e87101f6960d.html

HTML:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解(转)

————————————————

var s = "";
s += " 网页可见区域宽:"+ document.body.clientWidth;
s += " 网页可见区域高:"+ document.body.clientHeight;
s += " 网页可见区域宽:"+ document.body.offsetWidth + " (包括边线和滚动条的宽)";
s += " 网页可见区域高:"+ document.body.offsetHeight + " (包括边线的宽)";
s += " 网页正文全文宽:"+ document.body.scrollWidth;
s += " 网页正文全文高:"+ document.body.scrollHeight;
s += " 网页被卷去的高(ff):"+ document.body.scrollTop;
s += " 网页被卷去的高(ie):"+ document.documentElement.scrollTop;
s += " 网页被卷去的左:"+ document.body.scrollLeft;
s += " 网页正文部分上:"+ window.screenTop;
s += " 网页正文部分左:"+ window.screenLeft;
s += " 屏幕分辨率的高:"+ window.screen.height;
s += " 屏幕分辨率的宽:"+ window.screen.width;
s += " 屏幕可用工作区高度:"+ window.screen.availHeight;
s += " 屏幕可用工作区宽度:"+ window.screen.availWidth;
s += " 你的屏幕设置是 "+ window.screen.colorDepth +" 位彩色";
s += " 你的屏幕设置 "+ window.screen.deviceXDPI +" 像素/英寸";
alert (s);//-->
window.screen.availWidth 返回当前屏幕宽度(空白空间) 
window.screen.availHeight 返回当前屏幕高度(空白空间)
window.screen.width 返回当前屏幕宽度(分辨率值)
window.screen.height 返回当前屏幕高度(分辨率值)
window.document.body.offsetHeight; 返回当前网页高度
window.document.body.offsetWidth; 返回当前网页宽度

————————————————

2007/04/23 10:12 P.M.

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

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均无关)

测试代码:

 scrollLeft,scrollWidth,clientWidth,offsetWidth

 

 

测试代码:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “[url=http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]”>
<html xmlns=”[url=http://www.w3.org/1999/xhtml]http://www.w3.org/1999/xhtml[/url]” lang=”gb2312″>
<head>
<head>
<title> 代码实例:关于clientWidth、offsetWidth、clientHeight、offsetHeight的测试比较 </title>
<meta http-equiv=”content-type” content=”text/html; charset=gb2312″ />
<meta name=”author” content=”枫岩,CnLei.y.l@gmail.com”>
<meta name=”copyright” content=”[url=http://www.cnlei.com]http://www.cnlei.com[/url]” />
<meta name=”description” content=”关于clientWidth、offsetWidth、clientHeight、offsetHeight的测试比较” />
<style type=”text/css” media=”all”>
body {font-size:14px;}
a,a:visited {color:#00f;}
#Div_CnLei {

width:300px;
height:200px;
padding:10px;
border:10px solid #ccc;
background:#eee;
font-size:12px;
}
#Div_CnLei p {margin:0;padding:10px;background:#fff;}
</style>
<script type=”text/javascript”>
function Obj(s){

return document.getElementById(s)?document.getElementById(s):s;
}
function GetClientWidth(o){

return Obj(o).clientWidth;
}
function GetClientHeight(o){

return Obj(o).clientHeight;
}
function GetOffsetWidth(o){

return Obj(o).offsetWidth;
}
function GetOffsetHeight(o){

return Obj(o).offsetHeight;
}
</script>
</head>
<body>
<p>点击下面的链接:</p>
<div id=”Div_CnLei”>
<p><a href=”javascript:alert(GetClientWidth(‘Div_CnLei’));”>GetClientWidth();</a>  <a href=”javascript:alert(GetClientHeight(‘Div_CnLei’));”>GetClientHeight();</a></p>
<p><a href=”javascript:alert(GetOffsetWidth(‘Div_CnLei’));”>GetOffsetWidth();</a>  <a href=”javascript:alert(GetOffsetHeight(‘Div_CnLei’));”>GetOffsetHeight();</a></p>
</div>
<div id=”Description”>
<p><strong>IE6.0、FF1.06+:</strong><br />
clientWidth = width + padding = 300+10×2 = 320<br />
clientHeight = height + padding = 200+10×2 = 220<br />
offsetWidth = width + padding + border = 300+10×2+10×2= 340<br />
offsetHeight = height + padding + border = 200+10×2+10×2 = 240</p>
<p><strong>IE5.0/5.5:</strong><br />
clientWidth = width – border = 300-10×2 = 280<br />
clientHeight = height – border = 200-10×2 = 180<br />
offsetWidth = width = 300<br />
offsetHeight = height = 200</p>
</div>
</body>
</html>

类别:JavaScript 评论(0)

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/163027.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • vivado2018.3 安装(包含license)

    vivado2018.3 安装(包含license)Xilinx采用的是ISE和vivado;Altera采用的是quartusII。vivado2018.3安装本次安装问题描述:(1)上一次上官网下的比较慢,官网链接:https://china.xilinx.com/support/download/index.html/content/xilinx/zh/downloadNav/vivado-design-tools.html…

    2022年7月26日
    67
  • APP测试基本流程以及APP测试要点梳理,保证您看了不后悔!

    APP测试基本流程以及APP测试要点梳理,保证您看了不后悔!前言:相信很多刚刚步入测试行业的小伙伴对于APP测试不是很熟悉,这次我为大家提供一篇宝藏文章,希望大家喜欢,谢谢!一、APP测试基本流程1、流程图2、测试周期测试周期可按项目的开发周期来确定测试时间,一般测试时间为两三周(即15个工作日),根据项目情况以及版本质量可适当缩短或延长测试时间。3、测试资源测试任务开始前,检查各项测试资源。–产品功能需求文档;–产品原型图;–产品效果图;–测试设备;–其他。4、日报及产品上线报告(内部报告机制)–测试人员每天需对所测项目发送测试日报。(

    2022年5月5日
    112
  • idea intellij2021 激活码_在线激活「建议收藏」

    (idea intellij2021 激活码)这是一篇idea技术相关文章,由全栈君为大家提供,主要知识点是关于2021JetBrains全家桶永久激活码的内容IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.htmlMLZPB5EL5Q-eyJsaWN…

    2022年3月20日
    72
  • linux扩容VBoxManage

    linux扩容VBoxManage//查看虚拟磁盘空间信息,确认确实是需要扩容的虚拟硬盘。VBoxManageshowhdinfo”F:\oracleVirtualBox\workspace\centos1\centos1.vdi”//计算要扩容的空间大小,我这里是要扩展到100G(1024*1024*1024*100)。set/a1024*1024*1024//扩展虚拟硬盘空间,最后的数字替换成上面计算出的硬盘空…

    2022年6月1日
    44
  • linux将一个文件夹的内容复制到另一个文件夹_linux复制文件夹命令

    linux将一个文件夹的内容复制到另一个文件夹_linux复制文件夹命令1.前言本文主要讲解Linux系统如何使用命令行工具把文件复制到另一个文件夹或者目录。2.cp命令的选项和功能copy命令的功能是将给出的文件或目录拷贝到另一文件或目录中,同MSDOS下的copy命令一样,功能十分强大。语法:cp[选项]源文件或目录目标文件或目录说明:该命令把指定的源文件复制到目标文件或把多个源文件复制到目标目录中。该命令的各选项含义如下:-a该选项通常在拷贝目录…

    2022年8月23日
    6
  • margin 等高布局

    margin 等高布局

    2022年1月21日
    40

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号