执行完我的一组函数后如何执行某些操作?

发布于 2024-09-12 20:29:50 字数 356 浏览 6 评论 0原文

我有一组函数,我想做一些事情,比如在这些函数运行时显示加载动画!例如,当他们停下来时,我想显示警报。 这一切都在 jQuery 上。

有人有提示吗?

一些抽象代码:

//these are my functions:
function a(number){number=number*2};
a(1); a(2); a(3);
//While this functions are running i want to show a gif, for example!
//When the three callings this function has done, i want to show an alert

I have a set of functions, and I want to do something, like show a loading animation, while these functions are running! and when they stop i want to show an alert, for example.
All this on jQuery.

Anyone has a tip?

Some abstract code:

//these are my functions:
function a(number){number=number*2};
a(1); a(2); a(3);
//While this functions are running i want to show a gif, for example!
//When the three callings this function has done, i want to show an alert

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哆啦不做梦 2024-09-19 20:29:50

您的 JavaScript 与文档中的所有其他渲染在同一个线程中执行,因此在运行大量同步 JS(您的函数)之前进行 UI 更改是毫无意义的,只是为了随后反转 UI 更改。用户界面将保持不变。

执行您想要的操作仅在发生异步请求的情况下才有用,并且在这种情况下您必须依赖回调函数。

Your JavaScript is executed in the same single thread as all other rendering within the document and it is therefore pointless to make a UI change before running a lot of synchronous JS (your functions) only to then reverse the UI change. The UI will remain the same to the user.

Doing what you want would only be useful in situations where asynchronous requests are occurring, and in such situations you would have to rely on callback functions.

拥醉 2024-09-19 20:29:50

像这样:

// code to show loading message

function a(number){number=number*2};
a(1); a(2); a(3);

// code to hide loading message

代码是从上到下执行的,所以当函数运行时,加载消息将显示,因为它位于这些函数之前,当函数完成时,它将再次隐藏。

Like this:

// code to show loading message

function a(number){number=number*2};
a(1); a(2); a(3);

// code to hide loading message

The code is executed from top to bottom, so by the time function are running, the loading message will be showing because it is before those functions and when functions are done, it will hide again.

淡忘如思 2024-09-19 20:29:50

在调用函数之前,在屏幕上显示一些动画 gif

,在调用之后,函数将其删除并显示警报。

就是这样。

just before the call to the function display some animation gif on the screen

and just after the call the function remove it and show your alert.

thats it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文