无限滚动分页javascript实现问题

infinite scroll pagination javascript implementation issues

本文关键字:实现 问题 javascript 分页 滚动 无限      更新时间:2023-09-26

我正试图在jsfiddle中使用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;
                });
            };
        });

如果你启动控制台[f12在谷歌chrome]你会看到,当你到达页面的结束a 403禁止请求jsFiddle本身。是的,我认为问题在于你传递给contentPage的内容。

这是您的解决方案的工作小提琴http://jsfiddle.net/jsuHD/10/。当你从外部源加载html时,它允许你获得你想要的资源,它会像预期的那样工作。

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