这里的按钮从数据库加载数据.工作良好.
<li class="getmore" id="'.$post_id.'"><a>Load More Posts</a></li>
Run Code Online (Sandbox Code Playgroud)
如何在向下滚动到页面底部时自动单击此按钮.只是无限滚动.
我应该使用窗口滚动功能.如果是,那么如何在此代码中执行此操作.
我试过在这个函数中粘贴ajax代码但是没有工作.
编辑: 1.当我把Ajax放在scroll函数中时,它在getmore.php中显示mysql错误.2.如果我在滚动功能中放置了具有单击功能的按钮类,那么它会发射太快以至于多次加载相同的帖子.
$(document).scroll(function(){
if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
}
});
$('body').on('click','.getmore',function(){
var lastelement = $(this ).attr('id');
$.ajax({
type : 'GET',
url : 'getmore.php',
data : 'lastelement='+lastelement,
beforesend : function(){
$('.getmore').html('loading....');
},
success: function(data){
$('.getmore').remove();
$('#recs') .append(data) ;
}
});
});Run Code Online (Sandbox Code Playgroud)
<?php
$lastelement = $_REQUEST['lastelement' ];
include("connect2.php");
if ($lastelement!=''){
$query = "SELECT * FROM `posts` "
. "WHERE (id < " . $lastelement . " AND "
. "post_keywords like …Run Code Online (Sandbox Code Playgroud)在我的代码中,向下滚动时单击按钮 .getmore 。它从数据库加载数据。工作正常。我需要在每次点击后将其禁用 5 秒。我该如何设置这个延迟计时器?
或者是否可以在该功能触发后禁用该功能 5 秒?禁用按钮或禁用功能任何对我有用的东西。
$(window).scroll(function(){
if ($(document).height() <= $(window).scrollTop() + $(window).height()) {
// Here how can i set a delay time of 5 sec before next click
$('.getmore').click();
}
});
Run Code Online (Sandbox Code Playgroud)