2013-09-27 1 views
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; 
}); 
}); 

그래서, 내 질문은 내가 $에서 "load_more"함수를 호출 어떻게입니다 (창) .scroll?

감사합니다.

+0

함수 안에'$ (window) .scroll (function()'을 감쌀 필요가 없습니다 ... –

답변

2

그냥 그래서 약간의 수정도 필요

$(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; 
    }); 
}); 

희망이이 요구 사항을 충족, 버튼에 클릭을 트리거합니다.

+0

완벽하게 작동했습니다. 감사합니다. – Theodoros80

+0

다행입니다 :) –

관련 문제