0

データをロードするためにこのajaxスクリプトを作成しました。

$("#submit").click(function(e){
    e.preventDefault()  
    var loading = "<img src='/images/loading.gif' alt='Loading...' />";
    var scrolltop=$('#scrollbox').attr('scrollTop');
    var scrollheight=$('#scrollbox').attr('scrollHeight');
    var windowheight=$('#scrollbox').attr('clientHeight');
//  var post = $(this).attr("name") + "=" + $(this).val();
    var form_data = $('#search_form').serialize();// + "&" + post ;

    var scrolloffset=20;
    $('#search').html(loading);
    $.post("dosearch.php",form_data,function(newitems) {
        $('#content').append(newitems);
            });
        if(scrolltop>=(scrollheight-(windowheight+scrolloffset))){
            $.post("dosearch.php",form_data,function(newitems) {
        $('#content').append(newitems);
            });
        }     
        });
});

このスクリプトはフォームデータを取得してシリアル化し、投稿します。dosearch.phpその後、dosearchは、0,6で制限付きで検索したデータを投稿します。スクローラーが結果のdivの一番下に到達したら、より多くのコンテンツをフェッチしたいので、この関数を作成しました。この関数は、フォームデータと結果divのdivの数を取得します。 $ number、6を制限します。

function scroll_result(form_data){
    var loading = "<img src='/images/loading.gif' alt='Loading...' />";
    var scrolltop=$('#scrollbox').attr('scrollTop');
    var scrollheight=$('#scrollbox').attr('scrollHeight');
    var windowheight=$('#scrollbox').attr('clientHeight');
    var scrolloffset=20;
    var divnumber = $('#content').children().size();
    var form_data = form_data + "&size=" + divnumber;

    if(scrolltop>=(scrollheight-(windowheight+scrolloffset)))
    {
        //fetch new items
        $.post('dosearch.php', form_data, function(newitems){
        $('#content').append(newitems);
        });
    }
    setTimeout('scroll_result(form_data)', 1500);
}

この関数は機能しません、そして私はこれについていくつかの助けが必要です

前もって感謝します...

4

1 に答える 1

1

ここでサンプルのスクロールリスニングアプリケーションをセットアップしました:

http://jsfiddle.net/E2wj2/2/

あなたはあなたのためにスクロールイベントを聞く必要がありますscrollbox

$('#scrollbox').scroll(function(){
  console.log('scrolling');
  scrolltop=$('#scrollbox').attr('scrollTop');
  if(scrolltop>=(scrollheight-(windowheight+scrolloffset))) {
    //do whatever you wish to do
  }
});

お役に立てれば。

于 2012-12-08T07:30:47.883 に答える