2

是否可以指定我可以显示忙碌指示符的时间?

我的繁忙指标代码非常简单:

jQuery.ajaxSetup( {
    beforeSend:function ()
    {
        jQuery( "#busy-indicator" ).show();
    }, complete:function ()
    {
        jQuery( "#busy-indicator" ).hide();
    }
} );

但通常 Ajax 请求比出现指示器要快,因此我想将它显示为至少需要 1 秒的请求,这可能吗?或者你知道怎么做吗?

4

2 回答 2

7

这可以解决问题:

var timeout; 
jQuery.ajaxSetup( {
    beforeSend:function ()
    {
        if (timeout) { clearTimeout(timeout); }
        timeout = setTimeout(function() {
            jQuery( "#busy-indicator" ).show(); 
        }, 1000);
    }, 
    complete:function ()
    {
        if (timeout) { clearTimeout(timeout); } 
        jQuery( "#busy-indicator" ).hide();
    }
});
于 2012-07-23T10:00:06.230 回答
2
jQuery.ajaxSetup( {
    beforeSend:function ()
    {
        $( "#busy-indicator" ).stop(1,0).hide().delay(1000).show();
    }, 
    complete:function ()
    {
        $( "#busy-indicator" ).stop(1,0).hide();
    }
});

这也不行吗?

于 2012-07-23T10:37:29.643 回答