如何显示“忙”用jQuery指标? [英] How to display a "busy" indicator with jQuery?

查看:133
本文介绍了如何显示“忙”用jQuery指标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在网页中的特定点显示旋转的忙指示符?

How do I display a spinning "busy" indicator at a specific point in a web page?

我想在Ajax请求开始时启动/停止指示符/完成。

I want to start/stop the indicator when an Ajax request commences/completes.

这真的只是显示/隐藏动画gif的问题,还是有更优雅的解决方案?

Is it really just a matter of showing/hiding an animated gif, or is there a more elegant solution?

推荐答案

你可以只显示/隐藏一个gif,但你也可以将它嵌入到ajaxSetup中,这样就可以在每个ajax请求中调用它。

You can just show / hide a gif, but you can also embed that to ajaxSetup, so it's called on every ajax request.

$.ajaxSetup({
    beforeSend:function(){
        // show gif here, eg:
        $("#loading").show();
    },
    complete:function(){
        // hide gif here, eg:
        $("#loading").hide();
    }
});

需要注意的是,如果你想在没有加载微调器的情况下进行特定的ajax请求,你可以这样做:

One note is that if you want to do an specific ajax request without having the loading spinner, you can do it like this:

$.ajax({
   global: false,
   // stuff
});

这样我们所做的前一个$ .ajaxSetup不会影响的请求global:false

That way the previous $.ajaxSetup we did will not affect the request with global: false.

更多详细信息,请访问: http://api.jquery.com/jQuery.ajaxSetup

More details available at: http://api.jquery.com/jQuery.ajaxSetup

这篇关于如何显示“忙”用jQuery指标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆