我有一塊JS代碼,我只需要將這些部分連接起來就可以工作。 我的js代碼將加載更多的內容,從數據庫中提取。直到現在它工作得很好,當用戶點擊一個鏈接時,會加載更多。javascript滾動底部時執行函數
現在我想讓它在頁面接近尾聲時自動加載。 我的代碼:
加載更多功能
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?
謝謝!在按鈕
你不需要包裝'$(window).scroll(function()'裏面的函數... –