2013-07-29 34 views
0

我有这个脚本:弹出时消失的onmouseout

$(document).ready(function(){ 
      $('.infoLink').hover(function(){ 
      $('.shoutBox').hide(); 
      $(".shoutBox"+$(this).attr("id")+"").toggle();       
      }); 

      $('.closeLink').click(function(){ 
      $(this).closest(".shoutBox").toggle();     
      }); 
     }); 

我需要补充一点,这样,当参观者驻足徘徊在TE弹出链接弹出将dissappear。

弹出链接是一个小 “i” 按钮:

<a href="javascript:void(0);" class="infoLink rollover" id="box1"><img width="12" height="11" border="0" src="../path/to/randomimage.png" alt="" title="" /></a> 

我尝试添加:像

$('.infolink').onMouseOut(function(close){ 
$('.shoutBox').close(); 
$(".shoutBox"+$(this).attr("id")+"").toggle();        
}); 

东西......但是当你就会明白这...没有工作...

有人可以帮助我吗?

回答

0

悬停()事件处理程序必须有两个功能作为它的参数。那是

$(".some-class").hover(function1(), function2()); 

其他人回答的是正确的。但是如果你发现语法混乱,你可以试试

function mouseIn(){ 
    $('.shoutBox').hide(); 
    $(".shoutBox" + this.id).show();       
} 

function mouseOut(){ 
    $(".shoutBox" + this.id).hide();       
} 

现在你可以调用悬停事件处理程序。

$(".some-class").hover(mouseIn(), mouseOut()); 
+0

感谢百万以上;-) –

+0

投票我的答案> –

+0

也可能会接受它,如果你发现它很简单 –

1

.hover()事件处理程序需要回调方法,第一个是鼠标进入时调用,第二个是鼠标离开。如果没有提供第二个回调,第一个方法也会在鼠标离开时调用。

与回调,您呼叫.toggle()之前隐藏所有.shoutBox的问题,这将导致鼠标离开处理程序先隐藏当前元素,因为肘被调用后,它会得到再次显示

你需要

$('.infoLink').hover(function(){ 
    $('.shoutBox').hide(); 
    $(".shoutBox" + this.id).show();       
}, function(){ 
    $(".shoutBox" + this.id).hide();       
}); 
+0

太棒了!太感谢了! –

1
$('.infoLink').hover(function(){ 
      $('.shoutBox').hide(); 
      $(".shoutBox"+$(this).attr("id")+"").toggle();       
      }, function() { 
       $('.shoutBox').close(); 
       $(".shoutBox"+$(this).attr("id")+"").toggle();    
     });