2010-07-31 96 views
1

我必须犯一些明显的错误,但它似乎并没有工作。不能让hoverIntent jQuery插件工作

<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Untitled Document</title> 
<link href="css/style.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="js/jquery.js"></script> 
<script type="text/javascript" src="js/hoverIntent.js"></script> 

<script type="text/javascript"> 

$(document).ready(function() { 
$('.section').mouseover(function(){ 
    $('#nav2').fadeOut(0).animate({"height":"30px"}, 250); 

     }); 


$('#section1').hoverIntent(navSelect('.interior','0px')); 
$('#section2').hoverIntent(navSelect('.exterior','100px')); 
$('#section3').hoverIntent(navSelect('.view','200px')); 

function navSelect(section,selectorPosition){ 
return function(evt){ 
    if ($(section).is(':hidden')){ 
    $('.subSection').fadeOut(250); 
    $(section).delay(250).fadeIn(250); 
    $('#selector').animate({"left":selectorPosition},250); 
    }}} 


     }); 
</script> 

</head> 

.hover工作得很好,但是当我使用hoverIntent时,它什么也没有。

回答

0

hoverIntent doesn't have a single in/out function overload,从主页:

的jQuery .hover()可以采取既handlerInhandlerOut,/或/只是一个handlerIn。我的.hoverIntent()插件需要handlerInhandlerOut,/或/单个配置对象。它的设计目的不在于像.hover()这样的处理程序。下一个版本(r6)将更加灵活。

因此,要得到你想要的,你要么必须通过同样的方法两次,这样的:

$('#section1').hoverIntent(navSelect('.interior','0px'), navSelect('.interior','0px')); 

或者,有点清洁,您可以使用对象的过载,并通过这一次,但改变你的navSelect回到那个对象,而不是像这样:

function navSelect(section,selectorPosition){ 
    var func = function(evt){ 
    if ($(section).is(':hidden')) { 
     $('.subSection').fadeOut(250); 
     $(section).delay(250).fadeIn(250); 
     $('#selector').animate({"left":selectorPosition},250); 
    } 
    } 
    return { over: func, out: func }; 
} 
+0

感谢,在使用JavaScript和这整个返回对象的东西真的基本水平仍然伟大工程,IM是让人有些困惑对我来说 – 2010-07-31 04:48:38