delay the showing of a ajax loading gif using jQuery

后端 未结 4 693
后悔当初
后悔当初 2021-02-06 01:11

What is the best way to put a delay on the showing of a ajax-loader gif. When I click a button the loader gif shows and hides even if the time taken is a few hundred milli-secon

4条回答
  •  忘掉有多难
    2021-02-06 01:37

    Here is a fun way to do it. Replace $loader.show() with this:

    $("#loader").data('timeout', window.setTimeout(function(){ $("#loader").show()}, 1000));
    

    And your hide command with this:

    window.clearTimeout($("#loader").hide().data('timeout'));
    

提交回复
热议问题