1. 程式人生 > >用html5頁面引入了一個jquery外掛,實現平板上的向上滑動載入更多的功能

用html5頁面引入了一個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>