All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET,2.0移动开发入门之使用样式_[Asp.Net教程]
SQL数据库高级教程:学习 SQL JOIN_[SQL Server教程]
javascript实现图片幻灯片效果的源代码_JavaScript技术_编程技术
Varchar与char的区别_[SQL Server教程]
Javascript与asp.net,实现Ajax多文件无刷新上传_[Asp.Net教程]
.NET3.5和VS2008中的ASP.NET,AJAX_[Asp.Net教程]
Ajax实现页面loading效果!_[AJAX教程]
如何利用.NET,Framework使用RSS,feed_.net资料_编程技术
想学ASP.NET,来看看一些建议_.net资料_编程技术
ASP.NET开发经验(4):种简便地同时使用匿名与集成,Windows,验证的方法_[Asp.Net教程]
Reading number is top 10 pictures
So beauty, will let you spray blood8
Photographed the passion of the clients and prostitutes in the sex trade picture2
Play for Free show breast in a world of ice and snow
Seductive beauty of crime2
这是男生笨么?
中国女孩大胆自拍,显露完美身材3
刘亦菲写真集1
这只猪到底犯了什么错?
LiXiang early youth photo
Summer is most suitable for young people to travel in China5
Download software ranking
《小姨子》英文版37
Call Of Duty5
WebService在.NET中的实战应用教学视频 → 第4集
美女游泳记
Ashlynn Video4
ASP.NET.2.0.XML.高级编程(第3版)
matrix3
《小姨子》英文版22
尖东毒玫瑰A
Ashlynn Video5
delv published in(发表于) 2019/6/25 20:58:12 Edit(编辑)
不同浏览器对document.documentElement和document.body的scrollheight ,scrollTop,clientHeight以及判断滚动条是否滚动到页面最底部

不同浏览器对document.documentElement和document.body的scrollheight ,scrollTop,clientHeight以及判断滚动条是否滚动到页面最底部

前言:前段时间学习怎么写一个瀑布流的时候,就接触到document.documentElement和document.body的区别,然后今天查资料的时候看到这篇博客,遂转载记录在此。

两种特殊的文档属性可用来访问根节点:

  • document.documentElement
  • document.body

第一个属性可返回存在于 XML 以及 HTML 文档中的文档根节点。

第二个属性是对 HTML 页面的特殊扩展,提供了对 标签的直接访问。

【文档类型已申明】

IE

  1. document.documentElement.scrollHeight 浏览器所有内容高度
  2. document.documentElement.scrollTop 浏览器滚动部分高度,
  3. document.documentElement.clientHeight 浏览器可视部分高度,
  • document.body.scrollHeight 浏览器所有内容高度
  • document.body.scrollTop 始终为0
  • document.body.clientHeight 浏览器所有内容高度

FF

  1. document.documentElement.scrollHeight 浏览器所有内容高度 ,
  2. document.documentElement.scrollTop 浏览器滚动部分高度,
  3. document.documentElement.clientHeight 浏览器可视部分高度,
  • document.body.scrollHeight 浏览器所有内容高度
  • document.body.scrollTop 始终为0
  • document.body.clientHeight 浏览器所有内容高度

Chrome

  1. document.documentElement.scrollHeight 浏览器所有内容高度,
  2. document.documentElement.scrollTop 始终为0,
  3. document.documentElement.clientHeight 浏览器可视部分高度,
  • document.body.scrollHeight 浏览器所有内容高度
  • document.body.scrollTop 浏览器滚动部分高度
  • document.body.clientHeight 浏览器所有内容高度

【文档类型未申明】

IE

  1. document.documentElement.scrollHeight 浏览器可视部分高度,
  2. document.documentElement.scrollTop 始终为0,
  3. document.documentElement.clientHeight 始终为0,
  • document.body.scrollHeight 浏览器所有内容高度
  • document.body.scrollTop 浏览器滚动部分高度
  • document.body.clientHeight 浏览器可视部分高度

FF

  1. document.documentElement.scrollHeight 浏览器可视部分高度,
  2. document.documentElement.scrollTop 始终为0,
  3. document.documentElement.clientHeight 浏览器所有内容高度,
  • document.body.scrollHeight 浏览器所有内容高度
  • document.body.scrollTop 浏览器滚动部分高度
  • document.body.clientHeight 浏览器可视部分高度

Chrome

  1. document.documentElement.scrollHeight 浏览器可视部分高度,
  2. document.documentElement.scrollTop 始终为0,
  3. document.documentElement.clientHeight 浏览器所有内容高度,
  • document.body.scrollHeight 浏览器所有内容高度
  • document.body.scrollTop 浏览器滚动部分高度
  • document.body.clientHeight 浏览器可视部分高度

浏览器所有内容高度即浏览器整个框架的高度,包括滚动条卷去部分+可视部分+底部隐藏部分的高度总和

浏览器滚动部分高度即滚动条卷去部分高度即可视顶端距离整个对象顶端的高度。

综上

1、document.documentElement.scrollTop和document.body.scrollTop始终有一个为0,所以可以用这两个的和来求scrollTop

2、scrollHeight、clientHeight 在DTD已声明的情况下用documentElement,未声明的情况下用body

这里之前有误, document.compatMode 可以用来判断是否声明了DTD, 值为"BackCompat":未声明,值为"CSS1Compat":已声明。

下面就是如何判断滚动条是否滚动到页面最底部,也是写瀑布流的时候很关键的一部分代码。

window.onscroll = function (){

var marginBot = 0;

if (document.compatMode === "CSS1Compat"){

marginBot = document.documentElement.scrollHeight - (document.documentElement.scrollTop+document.body.scrollTop)- document.documentElement.clientHeight;

} else {

marginBot = document.body.scrollHeight - document.body.scrollTop- document.body.clientHeight;

}

if(marginBot<=0) {

//do something

}

};

document.compatMode用来判断当前浏览器采用的渲染方式。

  • BackCompat:标准兼容模式关闭。
  • CSS1Compat:标准兼容模式开启。

当document.compatMode等于BackCompat时,浏览器客户区宽度是document.body.clientWidth;
当document.compatMode等于CSS1Compat时,浏览器客户区宽度是document.documentElement.clientWidth。

浏览器客户区高度、滚动条高度、滚动条的Left、滚动条的Top等等都是上面的情况。





添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.