0
所以我想重構一些使用hoverIntent的jQuery鼠標。寄託都工作時,我呼籲個別對hoverIntent每個導航項目,但是當我嘗試使用下面的代碼,什麼也沒有發生第一鼠標懸停,那麼它的工作原理:hoverIntent不工作在第一個懸停
$('.navItem1').on('hover', function(){
navHoverIntent(this);
});
$('.navItem2').on('hover', function(){
navHoverIntent(this);
});
$('.navItem3').on('hover', function(){
navHoverIntent(this);
});
$('.navItem4').on('hover', function(){
navHoverIntent(this);
});
function navHoverIntent(className) {
//set some vars for use in hoverIntent
var currentDiv = $(className);
var cubeImg = currentDiv.find('img');
var childDivs = currentDiv.find('div');
var navTitle = childDivs[0];
var subNav = childDivs[1];
//now calling hoverIntent
currentDiv.hoverIntent({
over: function(){
if(cubeImg.css("display")=="block"){
navTitle.css("color","#262261");
}
currentDiv.css("backgroundColor","#d7d7d7");
$(subNav).show();
},
out: function(){
if(cubeImg.css("display")=="block"){
navTitle.css("color","#8CC640");
currentDiv.css("backgroundColor","#262261");
}else{
currentDiv.css("backgroundColor","transparent");
$("#subnav1").hide();
$("#subnav2").hide();
$("#subnav3").hide();
$("#subnav4").hide();
}
},
});
}
任何幫助,將不勝感激!