js滚动异步加载数据的思路

<body>

<div style="width:200px; height:1000px; border:1px solid red;" id="top_div"></div>

<script>
 window.onscroll = function(){ 
    var t = document.documentElement.scrollTop || document.body.scrollTop; //滚动条滚动的长度 
    var height=document.body.scrollHeight - window.screen.availHeight;  //网页页面整体高度  -  浏览器可见区域高度
   
    if( t >= height ) {
        //在此ajax异步加载数据显示
alert(height); $("div").last().after("<div style='width:200px; height:50px;'>"+Date.now()+"</div>"); } } </script> </body>

  

posted @ 2014-10-08 11:52  悲惨的大爷  阅读(640)  评论(0)    收藏  举报