你静候着秋天的温柔,留我在风景之外。把眼睛留给风光,把体重留给美食。我坐在椅子上,看日出复活;我坐在夕阳里,看城市的衰落。
本文实例讲述了JS简单实现滑动加载数据的方法。分享给大家供大家参考,具体如下:
//滑动
function getScrollTop()
{
var scrollTop = 0;
if (document.documentElement && document.documentElement.scrollTop) {
scrollTop = document.documentElement.scrollTop;
}else if (document.body) {
scrollTop = document.body.scrollTop;
}
return scrollTop;
}
//获取当前可视范围的高度
function getClientHeight()
{
var clientHeight = 0;
if (document.body.clientHeight && document.documentElement.clientHeight) {
clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
}else {
clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
}
return clientHeight;
}
//获取文档完整的高度
function getScrollHeight()
{
return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
}
//绑定事件
window.onscroll = function ()
{
if (getScrollTop() + getClientHeight() == getScrollHeight()) {
//dosomething
}
}
希望本文所述对大家JavaScript程序设计有所帮助。
以上就是JS简单实现滑动加载数据的方法示例。人生就是这样,你觉得一切都准备就绪了,认为自己可以为自己的理想去拼搏一把的时候老天爷却跟你开一个大大的玩笑,让你输的连苦笑的力气都没有。更多关于JS简单实现滑动加载数据的方法示例请关注haodaima.com其它相关文章!