区别:
body是dom对象里的body子节点,即
标签;
documentelement 是整个节点树的根节点root,即 标签;
没使用dtd情况即怪异模式backcompat下:
复制代码 代码如下:
document.documentelement.clientheight=0document.body.clientheight=618
使用dtd情况即标准模式css1compat下:
复制代码 代码如下:
document.documentelement.clientheight=618 document.body.clientheight=28(表示内容的高度)
因此提取浏览器的尺寸是要注意了。可以参考以下代码:
复制代码 代码如下:
if (document.compatmode == backcompat) {
cwidth = document.body.clientwidth;
cheight = document.body.clientheight;
swidth = document.body.scrollwidth;
sheight = document.body.scrollheight;
sleft = document.body.scrollleft;
stop = document.body.scrolltop;
}
else { //document.compatmode == css1compat
cwidth = document.documentelement.clientwidth;
cheight = document.documentelement.clientheight;
swidth = document.documentelement.scrollwidth;
sheight = document.documentelement.scrollheight;
sleft = document.documentelement.scrollleft == 0 ? document.body.scrollleft : document.documentelement.scrollleft;
stop = document.documentelement.scrolltop == 0 ? document.body.scrolltop : document.documentelement.scrolltop;
}