“忙碌等待”的最佳方式是动画是“位置可配置的”在jquery中? (即,显示操作在哪里)

发布于 2024-11-28 07:43:37 字数 971 浏览 6 评论 0原文

我打算有一个繁忙的等待旋转器,如本文所示:如何显示在 jQuery 中加载微调器? - 因为它是最干净且最容易实现的:

 $('#loadingDiv')
        .hide()  // hide it initially
        .ajaxStart(function() {
            $(this).show();
        })
        .ajaxStop(function() {
            $(this).hide();
        })
    ;

并将其与 http://www.ajaxload.info/

我的页面中有多个“视图”,即,我的页面的不同部分可以使用相应的 ajax 调用进行更新/修改。

我想将这个#loadingDiv“定位”到靠近“操作”的位置。我应该怎样去做呢?

想到的很少有事情:

  1. 在整个地方有多个 div 并将它们隐藏并根据相应的操作在每个元素中显示它们 - 似乎天真且浪费
  2. 有一个空的 来“保留”#loadingDiv - 当该范围内发生某些事情时显示它。但我不知道该怎么做...
  3. 还有别的吗?

基本上如何最好地处理位置繁忙等待/信号而不是单一的全局信号?或者是首选单一全局选项,即,要在每个活动的页面顶部/中心隐藏显示“固定”div?

只是想知道你们大多数人使用/喜欢哪个选项来解决类似的问题,以及您建议我如何去做......

I intend to have a busy waiting spinner as per shown in this post: How to show loading spinner in jQuery? - since it's the cleanest and easiest to implement:

 $('#loadingDiv')
        .hide()  // hide it initially
        .ajaxStart(function() {
            $(this).show();
        })
        .ajaxStop(function() {
            $(this).hide();
        })
    ;

and couple it up with the animations from http://www.ajaxload.info/

I have multiple "views" in my page i.e., different parts of my page can be updated/modified with the corresponding ajax calls.

I'd like to "position" this #loadingDiv close to where the 'action is' so to speak. How should I go about doing it?

Few things that come to mind:

  1. Have multiple divs all over the place and have them hidden and show them per element as per the corresponding action - seems naive and wasteful
  2. Have an empty <span></span> to 'hold' the #loadingDiv - show it when something happens in that span. I don't know how to do this though...
  3. Something else??

Basically how best to approach positional busy waiting/signalling rather than have a single global one? Or is the single-global option preferred i.e., To have a "fixed" div, hidden show up on the top/center of the page for every activity?

Just want to know which option most of you have used/preferred to tackle something like that and how do you suggest I go about it...

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

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

发布评论

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

评论(1

高冷爸爸 2024-12-05 07:43:37

有一些事情需要考虑:

如果用户在请求加载时与页面的其他部分交互,是否会导致问题?

在这种情况下,用灯箱(如透明覆盖层)遮挡整个 UI。

这些操作是否很小,与应用程序的其余部分无关?

使用本地定位微调器。如果它是一个按钮,请更改按钮的内容,例如。使用微调器将“保存行”更改为“保存...”。

如果请求很重要,但您想让用户乱搞,并且 GUI 很复杂

您只能覆盖屏幕的部分内容。 http://sfiddle.net/Lv9y5/39/

本地更新,非阻塞方式

使用 jQuery.position 从头开始​​创建 Spinner 对象。它应该有一个 .show(node) 和 .hide() 方法,也许还有一个 .setMessage(txt);
传递给 show 方法的 DOM 引用是用户单击的元素。有了参考,您可以使用 jQuery .position() 来确定加载 div 的绝对位置。加载 div 应放置在 BODY 元素之后。

There are some things to consider:

Can the user cause problems if he interacts with other parts of the page while the request is loading?

In this case block the whole UI with a lightbox like transparent overlay.

Are the actions tiny and small, irrelevant to the rest of the application?

Use the local, positioned spinner. If it's a button, change the button's contents from eg. "Save row" to "Saving..." with a spinner.

If the request is significant but you want to let the user to mess around, and the GUI is complex

You can overlay only parts of the screen. http://sfiddle.net/Lv9y5/39/

Local updates, the non blocking way

Use jQuery.position to create a Spinner object from scratch. It should have a .show(node) and .hide() method, and maybe a .setMessage(txt);
The DOM reference passed to the show method is the element the user clicked on. With the reference, you can use jQuery .position() to determine where to absolute position the loading div. The loading div should be placed after the BODY element.

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