简体   繁体   English

jQuery:在Ready事件期间提高感知的响应能力

[英]jQuery: Increase Perceived Responsiveness During the Ready Event

  • Launching code on document ready is a pillar of jQuery. 在文档就绪状态下启动代码是jQuery的支柱。
  • But sometimes, lengthy operations will be executed inside the ready event. 但有时,冗长的操作会在ready事件中执行。
    • For example, attaching multiple carousel instances to lengthy unordered lists will take some time. 例如,将多个轮播实例附加到冗长的无序列表将需要一些时间。

Question: 题:

How can I increase perceived responsiveness during the ready event? 在准备活动中如何增加感知到的响应能力?

For example: 例如:

  • Can I pop a thickbox instance with a 'Did You Know?' 我可以弹出带有“您知道吗?”的thickbox实例吗? section that obscures the underlying DOM manipulations? 掩盖了基本DOM操作的部分?
    • ...And then automatically close that thickbox instance when the ready event is complete? ...然后在ready事件完成后自动关闭该thickbox实例吗?

Every feedback that you give to the user will result in better perceived responsiveness. 您提供给用户的每个反馈都将带来更好的感知响应能力。 A loading image is classic - and well known (ie consistent with the user mind model). 加载图像是经典的-众所周知(即与用户思维模型一致)。 The thickbox may be rather annoying by itself - but if you combine it with a loading message, as most people in the game industry have already discovered, it will yield much better results by simultaneously educating the user and providing feedback. thickbox本身可能会很烦人-但是,如果将它与加载消息结合使用,正如游戏行业中大多数人已经发现的那样,它将通过同时教育用户和提供反馈来产生更好的结果。

[edit] [编辑]

Something like this: 像这样:

$(function() {
    tb_show(caption, url, imageGroup); // show thickbox

    /* lengthy operation here */

    tb_remove(); // remove thickbox
});

[/edit] [/编辑]

In addition to progress indicators, you can parallelise multiple operations using the Javascript setTimeout function with a very short timeout. 除了进度指示器外,您还可以使用Javascript setTimeout函数以非常短的超时时间并行化多个操作。 This effectively allows you to make use of multiple threads in the browser, running each operation asynchronously. 这有效地使您可以利用浏览器中的多个线程,以异步方式运行每个操作。

Only use this technique if your operations don't depend on each other for ordering or timing, and don't create too many timeouts at once or you might cause browser hangs due to increased memory usage. 仅当您的操作不相互依赖以进行排序或计时,并且一次也不会创建太多超时,否则您可能会因内存使用量增加而导致浏览器挂起,请使用此技术。

Note also that browsers have a minimum timeout, usually around 10-20ms, but it varies between browsers; 另请注意,浏览器的最短超时时间通常为10到20毫秒左右,但因浏览器而异。 it should be short enough to be unnoticeable. 它应该足够短以至于不被注意。 If you set a timeout of 0, it will default to the browser minimum. 如果将超时设置为0,它将默认为浏览器的最小值。

Here's a simple example for your carousel setup, splitting the lists into two groups: 这是轮播设置的一个简单示例,将列表分为两组:

setTimeout(function () {
    // code for attaching first carousel group
    // ...
}, 0);
setTimeout(function () {
    // code for attaching second carousel group
    // ...
}, 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM