为什么我的加载滚动不起作用,是ajax调用吗?

时间:2012-08-20 13:25:44

标签: php ajax jquery-ui

计划是在页面中添加带有加载滚动的滚动条。 2个问题:我的加载滚动不起作用&我不确定是否应该使用iframe来实现加载滚动。主要是因为我有一个jQuery可排序,可以在我的div中放置,我不确定我是否可以拖出iframe。任何想法将不胜感激

$(#win).scroll(function(){
//replaced window with #win, which is the id of the div containg database info
    if($(this)[0].scrollTop() == $(this)[0].height()- $(this).height()){

        //everytime we scroll we have this function activated
    //if statement is saying if we're at the bottom of the page
        //$('div#text').hide();
        $('div#loadMoreComments').show();
    //.show is showing the div above which has the loading animation

    $.ajax({
    url: "loadem.php?lastComment="+ $(".postedComment:last").attr("id"),
     //using get variable to say last comment is equal to + posted 
    //comment which is the last comment that's displayed &
    //that last comment has an id 
    success: function(html){
        if (html){
            $("#postedComment").append(html);
            //if we are at the bottom we will add comments to the page
            //and hide the animation
            $('div#loadMoreComments').hide();
            //$('div#text').show();


        }else{
            $('div#loadMoreComments').replaceWith("<div class='box'><center>Finished Loading</center></div>");
        //if theres no more to scroll then the finished loading will show
        }
    }
    });

    }
});

1 个答案:

答案 0 :(得分:0)

if((jQuery(window).scrollTop()) > (jQuery(document).height() - jQuery(window).height()))
{
 ...... YOUR CODE IS HERE.....
}

此代码将对您的网页进行连续分页。就我而言,它对可排序的,可丢弃的因素没有任何影响,因为你说它的分页div已经覆盖了所有的子元素。

希望这会有所帮助。