jQuery动态qtip显示div,但每次鼠标hover都变得越来越慢

我使用jQuery qTip插件来显示鼠标hover链接/ img的div。 我写了2个选项供使用,但两者都引起了麻烦。

V1:第一个版本显示工具提示,只是第二次将鼠标移到链接上。 在链接上重复鼠标之后,脚本似乎越来越慢,6/7次后我的浏览器几乎崩溃了…这里有什么问题?

V2:在我的第二个版本中,我尝试以正常的方式使用qTip,但是尝试将相关div的内容放入qTip内容,但是我们没有发生。 可能qTip插件不接受配置内的function,对吧?

你能看看这两个剧本并告诉我我做错了什么吗? 我不明白了。

   Project     jQuery(document).ready(function() { // hide all tooltip div's $(".tooltip_request").hide(); // V1 - show qtip layer - THIS ONE GETS VERY SLOW AFTER MOUSEOVER-ING several times?? $(".editrequest_v1").live('mouseover', function() { var request = $(this).attr('id'); // "request1" var name_tipdiv = "tooltip"+request; var div_content = $("#"+name_tipdiv).html(); $(this).qtip({ content: div_content, style: 'light', }); }); // V2 - show qtip layer - this one is not getting slow, but does not show the content $(".editrequest_v2").qtip({ content: function() { var request = $(this).attr('id'); // "request1" var name_tipdiv = "tooltip"+request; var div_content = $("#"+name_tipdiv).html(); return div_content; }, style: 'light', }); });    Show tooltip v1/content 1 - get slow and needs 2 times a mouseover before shows tooltip
Show tooltip v1/content 2 -get slow and needs 2 times a mouseover before shows toolti
CONTENT Tooltip 1
CONTENT Tooltip 2


Show tooltip v2/content 3 - does not show content in tip
Show tooltip v2/content 4 - does not show content in tip
CONTENT Tooltip 3
CONTENT Tooltip 4


非常感谢!

PS我是jQuery的新手 – 只需4周:-)

使用以下内容

 $(".editrequest_v2").each( function(){ $(this).qtip({ content: $("#tooltip"+$(this).attr('id')).html(), style: 'light', }); }); 

您第一次尝试的错误是您在每个鼠标hover时创建了一个新的工具提示。

你的第二次尝试有一个问题,你使用一个不允许的function..

尝试使用bind而不是live 。 仅当您要将事件绑定到将来使用AJAX加载的所有类时才使用实时。