您的位置:首页 > Web前端 > JavaScript

js 窗口滚动到一定高度时加载数据

2015-03-11 16:25 369 查看
<script type="text/javascript">
//当窗口滚动到一定高度时 某块页面开始加载数据
window.onload = function()
{
var oHeader = document.getElementById("header");
var height = oHeader.offsetHeight;

window.onscroll = function(){
//scrollTop的值
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
//窗口可视化高度
var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
document.getElementById("txt1").value="scrollTop:"+scrollTop+",height:"+height;
var oContent = document.getElementById("content");

if(scrollTop+clientHeight >height)
{
oContent.innerHTML = "<h1>正在加载中.....</h1>";

//延迟3秒执行
setTimeout(function(){
oContent.innerHTML = "<h1>scroll事件执行的代码块</h1>";
oContent.style.background="red";
},3000);

}
else
{
oContent.innerHTML="";
oContent.removeAttribute("style");
}
}
}
</script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: