完美辨析各种高度区别

 document.body.clientHeight(已过时)=document.documentElement.clientHeight(现在的)= document.documentElement.offsetHeight(过时,最好不用)= $(window).height();可见高度
=581
$(document).height(); 文档高度=4801
window.screen.height;屏幕分辨率高度781

网页可见区域宽: document.body.clientWidth; 
网页可见区域高: document.body.clientHeight; 
网页可见区域宽: document.body.offsetWidth (包括边线的宽); 
网页可见区域高: document.body.offsetHeight (包括边线的宽); 

在写个漂浮广告时遇到document.body.scrollTop和document.body.clientHeight为零的问题,在网上找到了原因:是因为html/jsp文件头部加了文档类型。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">

解决办法可以有两个(使用第二个好点)

1.去掉头部文档类型。

2.把document.body.scrollTop和document.body.scrollLeft这两个家伙改个名字:

document.documentElement.scrollTop 和document.documentElement.scrollLeft。

当然document.body.clientWidth和document.body.clientHeight也要改名字了,改为:document.documentElement.clientWidth和document.documentElement.clientHeight



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值