0

私はそれを機能させるために一緒に接続する必要があるJSコードを持っています。私のjsコードは、データベースからフェッチされたより多くのコンテンツをロードします.今までは、ユーザーがリンクをクリックすると、より多くのコンテンツがロードされます.

今、ページが終わりに近づいたときに自動的に読み込まれるようにしたいと考えています。私のコード:

さらに機能を読み込む

function myFunction() {
    $(window).scroll(function () {
        if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
            $("load_more"); < ---- ** HOW DO I CALL THE LOAD FUNCTION ?**
    }
    });

    $(function () {
        $(document).on("click", ".load_more", function () {
            var last_msg_id = $(this).attr("id");
            var device =<? php echo $idevice; ?>;
            if (last_msg_id != 'end') {
                $.ajax({//Make the Ajax Request
                    type: "POST",
                    url: "index_more.php",
                    data: "lastmsg=" + last_msg_id + "&aa=" + device,
                    beforeSend: function () {
                        $('a.load_more').html('<img src="img/loading.gif" />');
                    },
                    success: function (html) {
                        $("#more").remove();
                        $("ol#updates").append(html);
                    }
                });

            }
            return false;
        });
    });

だから、私の質問は、どのように $(window).scroll から "load_more" 関数を呼び出すのですか?

ありがとう!

4

1 に答える 1

3

ボタンをクリックするだけで、

$(window).scroll(function () {
   if ($(window).scrollTop() >= ($(document).height() - $(window).height() - 10)) {
      $(".load_more").trigger('click'); 
   }
});

そのため、いくつかの変更も必要でした。

$(function() {

    $(window).scroll(function () {
       if ($(window).scrollTop() >= ($(document).height() - $(window).height() - 10)) {
          $(".load_more").trigger('click'); 
       }
    });

    $(document).on("click",".load_more",function() {
        var last_msg_id = $(this).attr("id");
        var device=<?php echo $idevice; ?>;
        if(last_msg_id!='end'){
            $.ajax({//Make the Ajax Request
                type: "POST",
                url: "index_more.php",
                data: "lastmsg="+ last_msg_id+"&aa="+device,
                beforeSend:  function() {
                    $('a.load_more').html('<img src="img/loading.gif" />');
                },
                success: function(html){
                    $("#more").remove();
                    $("ol#updates").append(html);
                }
            });

        }
        return false;
    });
});

これが要件を満たしていることを願っています。

于 2013-09-27T07:57:31.793 に答える