clientHeight
大部分浏览器对 clientHeight 都没有什么异议,都认为是内容可视区域的高度,也就是说页面浏览器中可以看到内容的这个区域的高度,即然是指可看到内容的区域,滚动条不算在内。但要注意padding是算在内。其计算方式为clientHeight = topPadding + bottomPadding+ height - scrollbar.height。
offsetHeight
在IE6,IE7,IE8以及最新的的FF, Chrome中,在元素上都是offsetHeight = clientHeight + 滚动条 + 边框。
scrollHeight
scrollHeight是元素的padding加元素内容的高度。这个高度与滚动条无关,是内容的实际高度。
计算方式 :scrollHeight = topPadding + bottomPadding + 内容margix box的高度。
在浏览器中的区别在于:
IE6、IE7 认为scrollHeight 是网页内容实际高度,可以小于clientHeight。
FF、Chrome 认为scrollHeight 是网页内容高度,不过最小值是clientHeight。
注: 以上都是对于一般元素而方言的,body和documentElement的clientHeight, offsetHeight和scrollHeight在各个浏览器中的计算方式又不同。在所有的浏览器中,如果你想获取整个视窗的高度,你得用documentElement.clientHeight,因为body.clientHeight是由它的内容决定的。 关于body和documentElement的这些属性,则完全是另外一回事:
FF19
在body上设置overflow:scroll就是设置浏览器的滚动条,导致body.clientHeight永远都等于body.scrollHeight。
body
clientHeight:body.padding+ body.height(css设置或内容撑的);
offsetHeight:clientHeight+ body.border;
scrollHeight== clientHeight。
documentElement
clientHeight= window视窗高度 -scrollbar.width。
offsetHeight= body.offsetHeight + body.margin。
scrollHeight= 内容的高度(与body的height样式无关),但最小值是documentElement.clientHeight。
元素上
offsetHeight= padding + border + height。
clientHeight= padding + height - scrollbar.width。
scrollHeight>= clientHeight
从结果分析,FF认为scrollHeight的最小高度是clientHeight。
offsetLeft = 元素border左上角到window视窗原点的距离 或 到offsetParent的borderbox顶部的距离。
Chrome
body
clientHeight= body.padding + body.height(css设置或内容撑大);
offsetHeight = body.clientHeight + body.border;
scrollHeight= body.padding + 内容的高度(与height样式无关),但最小值是documentElement.clientHeight。
documentElement
clientHeight= window视窗高度 – 滚动条高度。
offsetHeight = body.offsetHeight + body.margin;
scrollHeight = 内容的高度(与body上的height无关),但最小值是documentElement.offsetHeight。
元素上
offsetHeight = padding + border + height。
clientHeight = padding + height - scrollbar.width。
scrollHeight >= clientHeight
Safari 5
body
clientHeight= body.padding + body.height(CSS或内容撑的);
offsetHeight= clientHeight + border;
scrollHeight= body.padding + 内容的高度(与height样式无关),但最小值是documentElement.clientHeight。
documentElement
clientHeight = window窗口大小 – 滚动条大小
offsetHeight = body.offsetHeight + body.margin
scrollHeight= 内容的高度(与body上的height无关),但最小值是documentElement.offsetHeight。
IE8
在IE8下,滚动条的大小是17个像素。
body
clientHeight= body.padding + body.height(css设置或内容撑大)
offsetHeight = clientHeight + body.border
scrollHeight =内容的高度(与body上的height无关),但最小值是clientHeight。
documentElement
clientHeight = 窗口大小(除去滚动条后)
offsetHeight = clientHeight + 滚动条大小 + body.border
scrollHeight=内容的高度(与body上的height无关),但最小值是body.offsetHeight+ margin。
元素上
offsetHeight = padding + border + height。
clientHeight = padding + height - scrollbar.width。
scrollHeight >= clientHeight
从结果分析,FF认为scrollHeight的最小高度是clientHeight。
offsetLeft = 元素border左上角到画布原点的距离 或 到offsetParent的borderbox顶部的距离。
IE7
在IE7中,body上设置的滚动条并不是窗口的滚动条,这个需要注意。
body
clientHeight= body.padding + height(css设置或内容撑大)– body上的滚动条。
offsetHeight= clientHeight + 滚动条的大小+body.border。
scrollHeight= 内容的高度(与body上的height无关)。
documentElement
clientHeight = window视窗大小(与滚动条的有无无关)
offsetHeight = clientHeight。
scrollHeight = body.offsetHeight + border.margin
元素
offsetHeight = padding + border + height。
clientHeight = padding + height - scrollbar.width。
scrollHeight = padding + 内容marginbox的高度
从结果分析,IE7认为scrollHeight可以小于clientHeight。
offsetLeft = 元素border box左上角到父容器(不是offsetParent)的borderbox左上角的距离。
IE6
在IE6中,与IE7类似, body上设置的滚动条并不是窗口的滚动条。
body
clientHeight = body.padding + body.height
offsetHeight = body.clientHeight + body.border + body上滚动条大小。
scrollHeight =内容的高度(与body上的height无关)。
documentElement
在IE6中,与IE7类似,虽然body上设置的滚动条并不是窗口的滚动条,但它的clientHeight和offsetHeight还算与其它浏览器想统一。
clientHeight = 窗口大小(除去窗口滚动条大小后)
offsetHeight =clientHeight + body.border
scrollHeight = body.offsetHeight + body.margin
元素
offsetHeight = padding + border + height。
clientHeight = padding + height - scrollbar.width。
scrollHeight = padding + 内容margin box的高度
从结果分析,IE6认为scrollHeight可以小于clientHeight。
相关推荐
在前端的日常开发中,我们经常无可避免的需要获取或者监听一些页面的属性,那么我们需要经常了解一些属性代表的含义才能更好地使用这些属性。特别是一下这些: 尺寸相关:offsetHeight、clientHeight、scrollHeight...
前言 最近由于公司业务要求,需要完成一个一键生成照片图片打印总图的功能 html2canvas是一个非常强大的截图插件,很多生成图片和打印的场景会用到它 ... height: dom.offsetHeight }).then(function
tag("div").style.height=tag("div").offsetHeight-10+"px" setTimeout("slideUp();",20); }else{ tag("div").style.display="none"; tag("img").src=...
zoomImg.parentNode.style.height = srcImg.height; function zoom(){ hidd.style.display=""; var elm = event.srcElement; h = elm.offsetHeight/zoomRate/2; //elm.offsetHeight/zoomRate/2 w = elm....
var BoxHeight = $G(ObjId).offsetHeight; //获取对象高度 var MinHeight = 5;//定义对象最小高度 var MaxHeight = 130;//定义对象最大高度 var BoxAddMax = 1;//递增量初始值 var Every_Add = 0.15;//每次的递(减)...
最近由于公司业务要求,需要完成一个一键生成照片图片打印总图的功能 html2canvas是一个非常强大的截图插件,很多生成图片和... height: dom.offsetHeight }).then(function (canvas) { var context = canvas.getCont
HTML5圆形波浪加载动画特效是一款原生html5 css3 canvas波浪滚动上升加载动画,圆形加载容器效果。 var wave = (function () { var ctx; var waveImage; var canvasWidth; var canvasHeight; var ...
return { Top: offsetTop, Left: offsetLeft, Width: offsetWidth, Height: offsetHeight } } 如果理解了的话就会觉得其实原理挺简单的,不过要想出来还是要一定创意才行,为想出这个方法的人致敬! 【切割预览】...
var height=e.offsetHeight; while(e=e.offsetParent) { t+=e.offsetTop; l+=e.offsetLeft; } } 假设 obj 为某个 HTML 控件。 obj.offsetTop 指 obj 距离上方或上层控件的位置,整型,单位像素。 obj.offsetLeft 指...
以下是我们给大家分享是实例代码: <html> <head> <title>我的第一个 HTML 页面<...<canvas id='cvs' width='1000' height=800> ... const height = cvs.offsetHeight; const ctx = cvs.getContex
上面用到了parentNode,这里顺便说说它跟offsetParent,parentElement的区别。 先看看parentNode在w3c的说明: The parent of this node. All nodes, except Document, DocumentFragment, and Attr may have a ...
offsetTop 可以获得 HTML 元素距离上方或外层元素的位置,style.top 也是可以... offsetLeft 与 style.left、offsetWidth 与 style.width、offsetHeight 与 style.height 也是同样道理。 scrollHeight: 获取对象的滚动
canvas.setAttribute('height', canvasHeight); wave.appendChild(canvas); waveImage = new Image(); waveImage.onload = function () { waveImage.onload = null; callback(); } ...
'top' : Math.min(Math.max(pos.y - this.offsetTop - parseInt(this.getElementsByTagName('div')[0].style.height) / 2,0),this.clientHeight - this.getElementsByTagName('div')[0].offsetHeight) + 'px', ...
win.height = win.contentDocument.body.offsetHeight; } else if(win.Document && win.Document.body.scrollHeight){ win.height = win.Document.body.scrollHeight; } } } } [removed]
在b/s开发中经常用到的javaScript技术整理 一、验证类 1、数字验证内 1.1 整数 1.2 大于0的整数 (用于传来的ID的验证) 1.3 负整数的验证 1.4 整数不能大于iMax 1.5 整数不能小于iMin 2、时间类 ...
var B = document.body.clientHeight-obj.offsetHeight obj.style.left = x + document.body.scrollLeft obj.style.top = y + document.body.scrollTop x = x + step*(xin?1:-1) if (x ) { xin = true; x = L} ...
c.offsetHeight,a.extend(c.style,{minHeight:"100px",height:"auto",padding:0,borderWidth:0}),a.support.minHeight=c.offsetHeight===100,a.support.selectstart="onselectstart"in c,b.removeChild(c).style....
top: expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight);} ul{ margin:0; padding:0; } .lxr{ background: url(chat_icon_5.gif) no-repeat scroll 12px -125px ...