js滚动条

/*滚动条在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();
}
};

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。