如何优化 qTip?
我一直在对我正在开发的应用程序进行一些分析,而 qTip 确实减慢了速度!我喜欢这个插件,但在文档就绪时添加提示需要花费近 2 秒的时间(页面上大约有 300 个提示)。我知道有很多技巧,但是有没有明显或不那么明显的方法来加快速度?
我在这里使用 2.0 的每日构建:
http://github.com/craga89/qtip
我用来添加提示的主要功能是:
var thingsToTip = $('.TipMe');
for (var currentItem, i = -1; currentItem = thingsToTip[++i]; ) {
currentItem = $(currentItem);
currentItem.qtip({
style: {
widget: false,
classes: 'ui-tooltip-light'
},
content: currentItem.attr('tooltip'),
position: {
at: 'bottomRight',
my: 'topleft',
adjust: {
screen: 'flip',
x: 0,
y: 0
}
}
});
}
现在我知道按类别选择并不是最有效的。但我尝试将其切换为跨度。TipMe,它只在 2069 秒中节省了大约 10 毫秒,因此为了可读性,我将其撤回。 我已经将其从使用 .each 切换为传统的 for 循环。这为我节省了大约 100 毫秒。与总运行时间相比,这又是九牛一毛。
我一直在使用 dynaTrace 来追踪缓慢的部分。
整个函数需要 2069 才能运行。 第1931章 那就是qtip功能。所以我对加速循环和选择器并不太感兴趣。他们很好。我需要减少实际 qtiping 所花费的时间。
希望我清楚我要做什么。
我愿意尝试几乎任何事情,如果有更有效的工具提示插件,我愿意放弃 qTip!
i've been doing some profiling on an app i'm working on and qTip is really slowing it down! I love this plugin but adding the tips on document ready is taking almost 2 whole seconds (about 300 tips on the page). I know it's a lot of tips, but is there anyway obvious or not so obvious ways to speed this up?
i'm using the daily build of 2.0 here:
http://github.com/craga89/qtip
and the main function i'm using to add the tips is this:
var thingsToTip = $('.TipMe');
for (var currentItem, i = -1; currentItem = thingsToTip[++i]; ) {
currentItem = $(currentItem);
currentItem.qtip({
style: {
widget: false,
classes: 'ui-tooltip-light'
},
content: currentItem.attr('tooltip'),
position: {
at: 'bottomRight',
my: 'topleft',
adjust: {
screen: 'flip',
x: 0,
y: 0
}
}
});
}
now i know selecting by class is not the most efficient. but i tried switching it to a span.TipMe and it only saved about 10 miliseconds out of 2069 so for readability i took it back out.
i've already switched it from using .each to being a traditional for loop. this saved me about 100 miliseconds. again, a drop in the bucket compared to the total running time.
i've been using dynaTrace to track down the slow parts.
the entire funcction takes 2069 to run.
1931 of that is the qtip function. so i'm not overly interested in speeding up the loop and selector. they are fine. i need to cut down on the time spent doing the actual qtiping.
hope it's clear what i'm looking to do.
i'm willing to try almost anything, and willing to ditch qTip if there is a more efficient tooltip plugin out there!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就像另一个人说的那样,只有在它们悬停或完成任何要求后才尝试附加它们。
Like the other guy said, try attaching them only once they've hovered or done whatever the requirement is.
我想说你只是一次添加太多。
您可以尝试使用
window.setTimeout();
一次加载它们,这样它们就不会挂起 UI?虽然我不确定这是否有效。或者,仅当用户将焦点放在该字段上时才应用 qTip,而不是事先加载所有内容......这显然会杀死您的页面。
用户实际上想要显示所有 300 个提示的可能性有多大?然而你正在加载它们......
实际上,你为什么要循环?这不是做同样的事情吗?
I'd say you're simply adding too many at once.
You could try loading them one at a time using
window.setTimeout();
so they don't hang up the UI? Though I'm not sure that will work.Alternatively, only apply the qTip when the user has focus on the field instead of loading them all prior...which is clearly killing your page.
What are the chances that the user will actually want to show all 300 tips? Yet you're loading them all...
Actually, why are you looping? Wouldn't this do the same thing?