2013-04-28 16 views
0

在我的网站,我有联系的东西像下面的图片列表中,他们每个人都有的相同类名称:jQuery的谅解备忘录事件的问题

enter image description here

一旦用户悬停那些中的任何一个链接,某些图像会在文本的右侧弹出。事情是这样的:

enter image description here

enter image description here

而当内容以外的用户将鼠标悬停。图像将使用鼠标移出功能消失。到目前为止,一切工作都很好。但是,因为他们都有同一个班级。只要您在任何这些文字链接中,图像就不会消失。这会导致这样的事情:

enter image description here

如果从一个内容到另一个将鼠标悬停速度不够快就会发生这种情况。只要你在任何这些链接容器中,它都不会消失。我怎样才能让单一的图像出现,并防止他人同时出现?

这是我用来处理这个问题的代码。

$('.my_link a').bind('mouseover', function(){ 
     var my_title = $(this).html(); 
     var title_width = parseInt($(this).width()); 
     var next = $(this).next(); 
     $.post('ajax/get_ajax_function.php',{my_title : my_title }, function(data){ 
      $(next).html(data).css('left', title_width+10+'px'); 
        //The $(next).html() has a name class of '.my_info_wrap' which I remove once the user hover out the link, and put it back it when they hover inside the content. 

     }); 
    }).mouseout(function(){ 
     $('.my_info_wrap').remove(); 
    }); 
+0

有点偏离主题,你应该使用'on'取代'bind' – 2013-04-28 16:55:40

+2

在题目:请您打造小提琴来显示这种行为? – 2013-04-28 16:56:15

+0

他们都不是同一个工作吗?但它仍然没有工作。 – user2329516 2013-04-28 16:56:53

回答

0

如何将之前拆除现有图像的新的:

$('.my_link a').bind('mouseover', function(){ 
      var my_title = $(this).html(); 
      var title_width = parseInt($(this).width()); 
      var next = $(this).next(); 
      $.post('ajax/get_ajax_function.php',{my_title : my_title }, function(data){ 
       $('.my_info_wrap').remove(); // <---------- HERE     
       $(next).html(data).css('left', title_width+10+'px'); 
         //The $(next).html() has a name class of '.my_info_wrap' which I remove once the user hover out the link, and put it back it when they hover inside the content. 

      }); 
     }).mouseout(function(){ 
      $('.my_info_wrap').remove(); 
     }); 
+0

它不工作,顺便说一句,有人已经建议我几分钟前完全相同的解决方案。但他删除了他的答案。 – user2329516 2013-04-28 17:08:02

+0

我找到了解决方案最终!我只需要添加$('。my_info_wrap')。remove();在显示内容之前在ajax里面。 – user2329516 2013-04-28 17:11:13

+0

是的,也只是想过。你也可以杀掉以前的ajax请求。 – 2013-04-28 17:14:29