jQuery:提高就绪事件期间的感知响应能力
- 在文档就绪时启动代码是 jQuery 的支柱。
- 但有时,会在就绪事件内执行冗长的操作。
- 例如,将多个轮播实例附加到冗长的无序列表将需要一些时间。
问题:
如何提高就绪事件期间的感知响应能力?
例如:
- 我可以弹出带有“你知道吗?”的 thickbox 实例吗?隐藏底层 DOM 操作的部分?
- ...然后在就绪事件完成时自动关闭该thickbox实例?
- Launching code on document ready is a pillar of jQuery.
- But sometimes, lengthy operations will be executed inside the ready event.
- 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?' section that obscures the underlying DOM manipulations?
- ...And then automatically close that thickbox instance when the ready event is complete?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您向用户提供的每一个反馈都会带来更好的感知响应能力。加载图像是经典的 - 并且众所周知(即与用户思维模型一致)。厚盒本身可能相当烦人 - 但如果将其与加载消息结合起来,正如游戏行业中的大多数人已经发现的那样,通过同时教育用户和提供反馈,它将产生更好的结果。
[编辑]
类似这样的东西:
[/编辑]
Every feedback that you give to the user will result in better perceived responsiveness. A loading image is classic - and well known (i.e. 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.
[edit]
Something like this:
[/edit]
除了进度指示器之外,您还可以使用 Javascript
setTimeout
函数以非常短的超时时间并行执行多个操作。这有效地允许您在浏览器中使用多个线程,异步运行每个操作。仅当您的操作在排序或计时方面不相互依赖时才使用此技术,并且不要一次创建太多超时,否则可能会因内存使用量增加而导致浏览器挂起。
另请注意,浏览器有一个最短超时时间,通常约为 10-20 毫秒,但不同浏览器的超时时间有所不同;它应该足够短以至于不引人注目。如果您将超时设置为 0,它将默认为浏览器的最小值。
这是轮播设置的一个简单示例,将列表分为两组:
In addition to progress indicators, you can parallelise multiple operations using the Javascript
setTimeout
function with a very short timeout. 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; it should be short enough to be unnoticeable. If you set a timeout of 0, it will default to the browser minimum.
Here's a simple example for your carousel setup, splitting the lists into two groups: