jquery解绑事件速度增加 [英] jquery unbinding events speed increases

查看:99
本文介绍了jquery解绑事件速度增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的内容幻灯片,我正在制作的页面开始使用大量的事件触发器。其中大约一半使用livequery插件。



我是否会通过在幻灯片之间卸载这些事件来看到速度提升,因此只有活动幻灯片绑定了事件?



本地的livequery也比livequery插件快得多吗?(因为它的功能肯定不那么重要)



也会是这样的:
http://dev.jquery.com/attachment/ticket/ 2698 / unload.js



解开livequery事件?



我真的只需要知道卸载/加载一个事件监听器需要多长时间,以及如果我让它们继续运行,它们正在吃多少个循环。此外,关于直播活动的任何信息都很棒。

解决方案

如果是native liveQuery 你的意思是 live() ,然后是, live()明显快于 liveQuery()。后者使用 setInterval 定期查询整个文档树中的新元素,而前者使用 event delegation



活动代表团获胜。简而言之, live()将在每个事件类型的文档上有一个处理程序注册(例如,点击),无论您使用多少选择器 live()



至于你的另一个问题,听起来你是绑定到每个幻灯片的元素,并想知道再绑定和绑定是否具有高性能?我会说WRT记忆,是的。 WRT CPU周期,没有。



要清楚,使用 liveQuery()方法CPU将永远不会睡眠。 / p>

I have a big content slideshow kinda page that I'm making that is starting to use a lot of event triggers. Also about half of them use the livequery plugin.

Will I see speed increases by unloading these events between slides so only the active slide has bound events?

Also is the native livequery significantly faster then the livequery plugin?(cause it's certainly less functional)

Also would something like this: http://dev.jquery.com/attachment/ticket/2698/unload.js

unbind livequery events as well?

I really just need to know how long it takes to unload/load an event listener vs how many cycles they are really eating up if I leave them running. Also any information on live events would be awesome.

解决方案

If by "native liveQuery" you mean live(), then yes, live() is significantly faster than liveQuery(). The latter uses setInterval to periodically query the entire document tree for new elements while the former uses event delegation.

Event delegation wins handsdown. In a nutshell, live() will have one handler on the document per event type registered (eg, click), no matter how many selectors you call live() with.

As for your other question, it sounds like you are binding to each slide's elements and want to know if unbinding and binding again is performant? I would say WRT memory, yes. WRT CPU cycles, no.

To be clear, with the liveQuery() approach CPU will never sleep.

这篇关于jquery解绑事件速度增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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