2013-04-08 77 views
0

我想在jsfiddle中使用javascript实现无限滚动分页,但我遇到问题才能正常工作。我没有看到滚动时的淡入淡出,当我到达内容的末尾时,我应该得到的消息是没有更多的数据,但它表示它正在等待更多数据。无限滚动分页javascript实现问题

原来的例子:http://andersonferminiano.com/jqueryscrollpagination/

我的实现:http://jsfiddle.net/jsuHD/

我添加了一个外部资源到的jsfiddle:scrollpagination.js

我想我的问题是使用JavaScript和不知道该怎么通过为contentPage

$(function(){ 
      $('#content').scrollPagination({ 
       'contentPage': 'http://jsfiddle.net/jsuHD/', // the url you are fetching the results 
       'contentData': {}, // these are the variables you can pass to the request, for example: children().size() to know which page you are 
       'scrollTarget': $(window), // who gonna scroll? in this example, the full window 
       'heightOffset': 10, // it gonna request when scroll is 10 pixels before the page ends 
       'beforeLoad': function(){ // before load function, you can display a preloader div 
        $('#loading').fadeIn(); 
       }, 
       'afterLoad': function(elementsLoaded){ // after loading content, you can use this function to animate your new elements 
        $('#loading').fadeOut(); 
        var i = 0; 
        $(elementsLoaded).fadeInWithDelay(); 
        if ($('#content').children().size() > 100){ // if more than 100 results already loaded, then stop pagination (only for testing) 
         $('#nomoreresults').fadeIn(); 
         $('#content').stopScrollPagination(); 
        } 
       } 
      }); 

      // code for fade in element by element 
      $.fn.fadeInWithDelay = function(){ 
       var delay = 0; 
       return this.each(function(){ 
        $(this).delay(delay).animate({opacity:1}, 200); 
        delay += 100; 
       }); 
      }; 

     }); 

回答

0

如果您启动控制台[谷歌浏览器中的f12]您会看到当您到达页面末尾时403禁止请求发送给jsFiddle本身。是的,我认为问题出在您传递给contentPage的问题上。

这是您的解决方案的工作小提琴http://jsfiddle.net/jsuHD/10/。当您从外部源加载html时,可以获得所需的资源,它可以按预期工作。

//load the html from external resource 
'contentPage': 'http://dl.dropbox.com/u/4001846/sample.html' 
+0

它是引发该错误的外部资源(滚动标记)。当复制到JavaScript的开始,一切工作。 http://jsfiddle.net/z9VAh/ – 2013-04-08 16:13:02