我怎么能强迫jQuery的动画发生时,窗口不集中 [英] How can I force Jquery animations to occur when the window is not focused

查看:99
本文介绍了我怎么能强迫jQuery的动画发生时,窗口不集中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了, 所以我建立一个基于AJAX的游戏。无论如何,它是多人,连接到服务器。它轮询服务器,获取更新所有的时间。但无论如何,游戏中有不同的游戏状态,必须根据游戏状态的动画图形用户界面。

Okay, So I am building an ajax based game. Anyway it is multiplayer, connects to a server. It polls the server, getting updates all the time. Anyway the game has different game states, and must animate the GUI based on the game state.

问题是,然而;当窗口不集中,jQuery的动画排队,不渲染。这意味着,假设某个用户走开了5分钟,回来,过时的动画一个巨大的队列开始由一个通过一个运行。

The problem is, however; When the window is not focused, jquery animations queue up and do not render. This means say a user walks away for 5 mins and comes back, a huge queue of obsolete animations start to run through one by one.

所以,我想知道是否有任何方式强迫jQuery的动画运行时,他们被称为,而不是等待一个焦点窗口?

So I was wondering if there is any way to force jquery animations to run when they are called and not wait for a focused window?

有关为什么发生这种情况的更多信息,请参阅其他注意事项,在这里 HTTP jQuery的文档:// API。 jquery.com/fadeIn/

For further information on why this happens, read Additional Notes, in the jquery documentation here http://api.jquery.com/fadeIn/

干杯,乔希

推荐答案

根据不同的动画,你可以通过调用获得动画队列中的主体元素 .queue(),如果它的长度超过一个元素,你可以调用 .clearQueue()。当然,你必须要小心,不要乱了布局,因为它会删除所有动画。

Depending on the animations, you could add onfocus event on the body element that gets the animation queue by calling .queue() and if it's longer than one element, you could call .clearQueue(). Of course you'd have to be careful not to mess up the layout, since it removes all the animations.

你也可以尝试做 jQuery.fx.off = TRUE 如果该列表的长度超过一个元素。这应该设置所有动画的持续时间为0,这应导致所有排队的动画即刻被完成的,并以使动画再次,将值设置为false。然而,因为我还没有尝试过自己,我不知道这是否设置只对尚未运行(已经在排队等候)的动画或只尚未被添加到这些时间一个队列。如果后一种情况是真实的,你可以通过队列循环,并设置每个时间手动0。

Also you could try doing jQuery.fx.off = true if the list is longer than one element. This should set the duration of all animations to 0, which should result in all of the queued animations being finished instantly, and to enable animations once again, set the value to false. However, since I haven't tried it myself, I'm not sure if it sets the duration only on the animations that haven't yet been run (already in a queue) or on only those that haven't yet been added to a queue. If the latter case is true, you could loop through the queue and set each duration to 0 manually.

这篇关于我怎么能强迫jQuery的动画发生时,窗口不集中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆