Jquery頁面滾動動態加載數據,頁面下拉自動加載內容


<!DOCTYPE=html>
<html>
<head>
<script src="js/jquery.js" type="text/javascript"></script>

   <script type="text/javascript">
    $(document).ready(function(){
        var range = 50;             //距下邊界長度/單位px
        var elemt = 500;           //插入元素高度/單位px
        var maxnum = 20;            //設置加載最多次數
        var num = 1;
        var totalheight = 0; 
        var main = $("#content");                     //主體元素
        $(window).scroll(function(){
            var srollPos = $(window).scrollTop();    //滾動條距頂部距離(頁面超出窗口的高度)
            
            //console.log("滾動條到頂部的垂直高度: "+$(document).scrollTop());
            //console.log("頁面的文檔高度 :"+$(document).height());
            //console.log('瀏覽器的高度:'+$(window).height());
            
            totalheight = parseFloat($(window).height()) + parseFloat(srollPos);
            if(($(document).height()-range) <= totalheight  && num != maxnum) {
                main.append("<div style='border:1px solid tomato;margin-top:20px;color:#ac"+(num%20)+(num%20)+";height:"+elemt+"' >hello world"+srollPos+"---"+num+"</div>");
                num++;
            }
        });
    });
    </script>
</head>
<body>
    <div id="content" style="height:960px">
        <div id="follow">this is a scroll test;<br/>    頁面下拉自動加載內容</div>
        <div style='border:1px solid tomato;margin-top:20px;color:#ac1;height:800' >hello world test DIV</div>
        
    </div>
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM