没有合适的资源?快使用搜索试试~ 我知道了~
根据例子来理解scrollHeight,clientHeight,scrollTop的区别
需积分: 50 7 下载量 7 浏览量
2009-01-14
16:54:06
上传
评论
收藏 2KB TXT 举报
温馨提示
试读
2页
包含以下内容: function test(){ var infoHeight = document.getElementById(”info”).scrollHeight; //scrollHeight 为层实际的高度,有实际有多高就多高,与当前网页高度无关。
资源推荐
资源详情
资源评论
在子鼠的博客看到了2个js的例子,正好是我一直搞不清的height系列。。
2篇博客分别是《让一行页脚保持在底部》和《右下角广告代码-已测-支持FIREFOX IE7 IE6》。
我对里面代码根据自己的理解添加了注释。我觉得还是蛮口语化的,大家随便看看。
这是《让一行页脚保持在底部》的注释,效果可以点此
function test(){
var infoHeight = document.getElementById(”info”).scrollHeight;
//scrollHeight 为层实际的高度,有实际有多高就多高,与当前网页高度无关。
var bottomHeight = document.getElementById(”bottom”).scrollHeight;
var allHeight = document.documentElement.clientHeight;
//clientHeight 为层在当前屏幕的高度,非该层的实际高度
var bottom = document.getElementById(”bottom”);
//获取bottom
if((infoHeight + bottomHeight) <allHeight){ //如果"info层的高度"加"bottom层的高度"小于"当前屏幕的高度"
bottom.style.position = "absolute"; //定义bottom的position为absolute
bottom.style.bottom = "0"; //bottom属性设为0.
}else{
bottom.style.position = "";
bottom.style.bottom = "";
}
setTimeout(function(){test();},10); //当内容减少,窗口缩小,依然保持在底部
}
test();
《右下角广告代码-已测-支持FIREFOX IE7 IE6》的注释,效果可以点此
//
2篇博客分别是《让一行页脚保持在底部》和《右下角广告代码-已测-支持FIREFOX IE7 IE6》。
我对里面代码根据自己的理解添加了注释。我觉得还是蛮口语化的,大家随便看看。
这是《让一行页脚保持在底部》的注释,效果可以点此
function test(){
var infoHeight = document.getElementById(”info”).scrollHeight;
//scrollHeight 为层实际的高度,有实际有多高就多高,与当前网页高度无关。
var bottomHeight = document.getElementById(”bottom”).scrollHeight;
var allHeight = document.documentElement.clientHeight;
//clientHeight 为层在当前屏幕的高度,非该层的实际高度
var bottom = document.getElementById(”bottom”);
//获取bottom
if((infoHeight + bottomHeight) <allHeight){ //如果"info层的高度"加"bottom层的高度"小于"当前屏幕的高度"
bottom.style.position = "absolute"; //定义bottom的position为absolute
bottom.style.bottom = "0"; //bottom属性设为0.
}else{
bottom.style.position = "";
bottom.style.bottom = "";
}
setTimeout(function(){test();},10); //当内容减少,窗口缩小,依然保持在底部
}
test();
《右下角广告代码-已测-支持FIREFOX IE7 IE6》的注释,效果可以点此
//
资源评论
etongchina
- 粉丝: 6
- 资源: 55
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功