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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 网站死链查询-在线网站死链查询提交工具免费

    网站死链查询-在线网站死链查询提交工具免费网站死链查询,什么是网站死链,网站死链“死链是指服务器的地址已经改变了.无法找到当前地址位置,包括协议死链和内容死链两种形式。死链出现的原因有网站服务器设置错误;某文件夹名称修改,路径错误链接变成死链等。网站太多的死链会导致网站降权严重着甚至会导致网站被K。当然也有部分小伙伴为了得到更多的提交,专门制作死链主动提交(这属于SEO中一种另类的手法,不建议轻易尝试)更多更全的SEO工具查看图片教程。有一句,“事不过三”,就是说,同样一个新闻,第一次听到,网站死链查询会惹起很多人关注,第二次,关注的人会减少,到了

    2022年7月23日
  • curl 的用法指南「建议收藏」

    curl 的用法指南「建议收藏」curl 的用法指南

    2022年4月23日
  • HDU 5046 Airport(DLX反复覆盖)

    HDU 5046 Airport(DLX反复覆盖)

    2022年1月24日
  • java clone()_java throwable

    java clone()_java throwable克隆是一种基本的编程模式。事实上,Java在很多方面可能实现得很差,但这丝毫没有减少克隆的必要性。而且,很容易实现克隆,无论你希望它如何工作,浅层的,深层的,混合的,无论什么。如果愿意的话,甚至可以为函数使用clone名称,而不实现Cloneable。假设我有类A、B和C,其中B和C是从A派生的。如果我有一个A类型的对象列表,如下所示:ArrayListlist1;ArrayListlist2…

    2022年10月10日
  • WebGrid 在asp.net mvc中的使用和理解(译)

    WebGrid 在asp.net mvc中的使用和理解(译)1:思路webgrid就是表格,一行行记录,代表一个个模型,因此,我们只需要在models文件夹建立模型,在控制器生成模型列表,把列表作为模型传入视图(或者绑定强类型视图,这个类型至少大于等于此模型列

    2022年7月3日
  • elasticSearch字段类型大全

    elasticSearch字段类型大全ES字段类型核心数据类型String类型:text、keyworknumber类型:long,integer,short,byte,double,float,half_float,scaled_floatdate类型:dateboolean类型:booleanbinary类型:binaryrange类型:integer_range,float_range,long_range,double_range,date_range复杂数据类型对象数据类型:object用

    2022年5月22日

发表回复

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

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