I have a piece of JS code where i just have to connect the pieces together to make it work. My js code will load more content,fetched from database.Until now it is working just fine,when a user clicks a link,will load more.
Now i want to make it automatically load when the page is near the end. My code:
Load more function
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;
});
});
So,my question is how do i call the "load_more" function from $(window).scroll?
Thanks!
$(window).scroll(function ()inside function...