码迷,mamicode.com
首页 > Web开发 > 详细

js滚动条

时间:2015-05-18 12:15:01      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:

/*滚动条在Y轴上的滚动距离*/
function ScrollTop()
{
var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0;
if (document.body)
{
bodyScrollTop = document.body.scrollTop;
}
if (document.documentElement)
{
documentScrollTop = document.documentElement.scrollTop;
}
scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
return scrollTop;
}
/*文档的总高度*/
function ScrollHeight()
{
var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0;
if (document.body)
{
bodyScrollHeight = document.body.scrollHeight;
}
if (document.documentElement)
{
documentScrollHeight = document.documentElement.scrollHeight;
}
scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
return scrollHeight;
}
/*浏览器视口的高度*/
function WindowHeight()
{
var windowHeight = 0;
if (document.compatMode == "CSS1Compat")
{
windowHeight = document.documentElement.clientHeight;
} else
{
windowHeight = document.body.clientHeight;
}
return windowHeight;
}
window.onscroll = function()
{
if (ScrollTop() + WindowHeight() + 5 >= ScrollHeight())
{
More();
}
};

js滚动条

标签:

原文地址:http://www.cnblogs.com/ghelement/p/4511328.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!