仅在50毫秒后显示微调器

编程入门 行业动态 更新时间:2024-10-10 08:18:12
本文介绍了仅在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毫秒后显示微调器

本文发布于:2023-05-31 13:58:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/392992.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!