2

我找到了这些使用 Jquery 进行无限滚动的演示,但我不知道如何使用它们,因为没有提供它们的源。如果有人喜欢他们,请您解决这个问题吗?

我为 Demo 5 尝试了这段代码,但没有成功。

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
 <script type="text/javascript">
$(document).ready(function(){
    function lastAddedLiveFunc()
    {
        $('div#lastPostsLoader').html('<img src="bigLoader.gif">');

        $.get("loadmore.php", function(data){
            if (data != "") {
                //console.log('add data..');
                $(".items").append(data);
            }
            $('div#lastPostsLoader').empty();
        });
    };

    //lastAddedLiveFunc();
    $(window).scroll(function(){

        var wintop = $(window).scrollTop(), docheight = $(document).height(), winheight = $(window).height();
        var  scrolltrigger = 0.95;

        if  ((wintop/(docheight-winheight)) > scrolltrigger) {
         //console.log('scroll bottom');
         lastAddedLiveFunc();
        }
    });
});
</script>
</head>
<body>
<ul class="items">
   <li>content</li>
   <li>content</li>
   <li>content</li>
   <li>content</li>
   <li>content</li>
   <li>content</li>

   <li>content</li>
   <li>content</li>
   <li>content</li>
   <li>content</li>
   <li>content</li>
   <li>content</li>
   <li>content</li>
   <li>content</li>
   <li>content</li>                   
  </ul>

<div id="lastPostsLoader"></div>
</body>
</html>
4

1 回答 1

1

试试这个:

function lastAddedLiveFunc(){
    $('div#lastPostsLoader').html('<img src="bigLoader.gif">');

    $.get("loadmore.php", function(data){
        if (data != "") {
            //console.log('add data..');
            $(".items").append(data);
        }
        $('div#lastPostsLoader').empty();
    });
}

$(document).ready(function(){
   $(window).scroll(function(){

      var wintop = $(window).scrollTop(), docheight = $(document).height(), winheight = $(window).height();
      var  scrolltrigger = 0.95;

      if  ((wintop/(docheight-winheight)) > scrolltrigger) {
       //console.log('scroll bottom');
       lastAddedLiveFunc();
      }
  });
});
于 2013-01-29T11:20:22.207 回答