仅在50毫秒后显示微调器 [英] show spinner only after 50ms

查看:79
本文介绍了仅在50毫秒后显示微调器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,其中发生了许多ajax操作.我显示了一个微调器,指示请求正在处理中.

I have a page where a lot of ajax action is taking place. I show a spinner to indicate the request is being processed.

其中一些请求时间很长,其中一些请求很快.当反应很快到来时,那些纺纱厂更是讨厌而不是援助.

Some of those requests long time and some of them are quick. When the response comes quickly then those spinners are more of a nuisance than an aid.

这就是我想要的.自请求提交以来超过50毫秒,仅显示微调框.

This is what I wanted. Display the spinner only if it has been more than 50ms since the request was submitted.

这意味着启动请求时,微调器开始计时.如果响应在50毫秒之前到来,则响应将使微调框隐藏.

It means when the request is initiated spinner starts counting time. If a response comes before 50ms then response will make spinner hide.

但是,如果在50毫秒内未出现响应,则显示微调器.

However if response does not come in 50ms then show spinner.

已经有任何可以帮助我入门的插件了.

Is there any plugin already out there that might help me get started.

谢谢

推荐答案

可以使用原始JavaScript轻松完成此操作.无需插件.

This can be easily accomplished using vanilla JavaScript. No need for a plug-in.

要在50毫秒后显示微调器:

To show the spinner after 50ms:

var t = setTimeout("showSpinner()", 50);

如果调用在50ms之前成功(在AJAX回调内部),然后取消超时:

And then to cancel the timeout if the call succeeds before 50ms (inside the AJAX callback):

clearTimeout(t);

这篇关于仅在50毫秒后显示微调器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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