我想知道是否只有当变量在一段时间内为 true 时才可以在 jquery 中触发 if 语句。像这样的 if(variable == true//for #ms){do ..}。我需要这个,以免立即触发 ajax 后加载。 提前致谢,马特
jQuery(document).ready(function($) {
$(function()
{
$('#reviewspostscont').each(
function()
{
$(this).jScrollPane(
{
horizontalDragMaxWidth : 100
}
);
var api = $(this).data('jsp');
var throttleTimeout;
$(window).bind(
'resize',
function()
{
if (!throttleTimeout) {
throttleTimeout = setTimeout(
function()
{
api.reinitialise();
throttleTimeout = null;
},
50
);
}
}
);
var count = 2;
$(this).bind(
'jsp-scroll-x',
function(event, scrollPositionX, isAtLeft, isAtRight)
{
var count = 2;
if (isAtRight == true) {
ajaxJScrollLoader();
}
}
);
function ajaxJScrollLoader()
{
api.getContentPane().append(
loadArticle(count),
count++
);
// we could call "pane.jScrollPane(settings)" again but it is
// more convenient to call via the API as then the original
// settings we passed in are automatically remembered.
api.reinitialise();
}
}
)
});
function loadArticle(pageNumber){
$.ajax({
url: "<?php bloginfo('wpurl') ?>/wp-admin/admin-ajax.php",
type:'POST',
data: "action=infinite_scroll&page_no="+ pageNumber + '&loop_file=loop-reviews',
success: function(html){
$(".jspPane").append(html); // This will be the div where our content will be loaded
}
});
return false;
}
});
最佳答案
您可以使用设置间隔功能并定期检查:
var interval = setInterval(function(){
//Check what you want here
}, 1000);
第二个参数(1000)是时间(以毫秒为单位)
如果您需要停止此循环,只需执行以下操作:
clearInterval(interval);
关于javascript - jQuery if 语句,检查变量是否在一段时间内为 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25406137/