2012-04-24 57 views
0

我分裂的功能为hoverintent和工作,但现在的div不隐藏,直到鼠标离开?jQuery hoverIntent - 当我分割函数时,我做错了什么?

我写了这个工作正常,我是新来的jquery,你可能会告诉。

$("img.nexthover").hover(
function() { this.src = this.src.replace("_off", "_on"); 
}, 
function() { this.src = this.src.replace("_on", "_off"); 
}); 
$('#A,#B,#C,#D,#E,#F,#G,#H,#I,#J').addClass('nextHide'); 
$('.nextbuttonA').hover(function() { 
$('#A.nextHide').fadeIn("slow");   
$('#B,#C,#D,#E,#F,#G,#H,#I,#J.nextHide').fadeOut(); 
}); 
$('.nextbuttonB').hover(function() { 
$('#B.nextHide').fadeIn("slow"); 
$('#A,#C,#D,#E,#F,#G,#H,#I,#J.nextHide').fadeOut(); 
});  
$('.nextbuttonC').hover(function() { 
$('#C.nextHide').fadeIn("slow"); 
$('#A,#B,#D,#E,#F,#G,#H,#I,#J.nextHide').fadeOut(); 
});   
$('.nextbuttonD').hover(function() { 
$('#D.nextHide').fadeIn("slow"); 
$('#A,#B,#C,#E,#F,#G,#H,#I,#J.nextHide').fadeOut(); 
}); 
$('.nextbuttonE').hover(function() { 
$('#E.nextHide').fadeIn("slow"); 
$('#A,#B,#C,#D,#F,#G,#H,#I,#J.nextHide').fadeOut(); 
}); 
$('.nextbuttonF').hover(function() { 
$('#F.nextHide').fadeIn("slow"); 
$('#A,#B,#C,#D,#E,#G,#H,#I,#J.nextHide').fadeOut(); 
}); 
$('.nextbuttonG').hover(function() { 
$('#G.nextHide').fadeIn("slow"); 
$('#A,#B,#C,#D,#E,#F,#H,#I,#J.nextHide').fadeOut(); 
}); 
$('.nextbuttonH').hover(function() { 
$('#H.nextHide').fadeIn("slow"); 
$('#A,#B,#C,#D,#E,#F,#G,#I,#J.nextHide').fadeOut(); 
}); 
$('.nextbuttonJ').hover(function() { 
$('#I.nextHide').fadeIn("slow"); 
$('#A,#B,#C,#D,#E,#F,#G,#H,#J.nextHide').fadeOut(); 
}); 
$('.nextbuttonK').hover(function() { 
$('#J.nextHide').fadeIn("slow"); 
$('#A,#B,#C,#D,#E,#F,#G,#H,#I.nextHide').fadeOut(); 
}); 
$('#A,#B,#C,#D,#E,#F,#G,#H,#I,#J').click(function(){ 
    $('.nextHide').fadeOut(); 
}); 

要获得hoverIntent工作我分裂这样的功能:

$("img.nexthover").hover(
function() { this.src = this.src.replace("_off", "_on"); 
}, 
function() { this.src = this.src.replace("_on", "_off"); 
}); 
$('#A,#B,#C,#D,#E,#F,#G,#H,#I,#J').addClass('nextHide'); 

$('.nextbuttonA').hoverIntent(function() { 
$('#A.nextHide').fadeIn("slow"); 
}, function() { 
$('#B,#C,#D,#E,#F,#G,#H,#I,#J.nextHide').fadeOut(); 
}); 

$('.nextbuttonB').hoverIntent(function() { 
$('#B.nextHide').fadeIn("slow"); 
}, function() { 
$('#A,#C,#D,#E,#F,#G,#H,#I,#J.nextHide').fadeOut(); 
}); 

---etc---- 

但现在的格是不是隐藏,直到你离开按钮像以前一样? 对不起,如果这太新手了,我通过跳进来教自己...

+0

检查这些资源http://addyosmani.com/resources/essentialjsdesignpatterns/book/,http://www.slideshare.net/mathiasbynens/how-dry-impacts-javascript-performance-faster-javascript-execution-for -the懒惰开发商 – elclanrs 2012-04-24 23:32:47

回答

0

得到它,如果你有兴趣,我的jQuery语法可能会更好,但我在另一个程序工作,所以我有限制如何我可以进入HTML

$("img.nexthover").hover(
function() { this.src = this.src.replace("_off", "_on"); 
}, 
function() { this.src = this.src.replace("_on", "_off"); 
}); 
$('#A,#B,#C,#D,#E,#F,#G,#H,#I,#J').addClass('nextHide'); 

$('.nextbuttonA').hoverIntent(function() { 
$('#A').fadeIn("slow");$('#B,#C,#D,#E,#F,#G,#H,#I,#J').fadeOut(); 
}, function() { 
$('#B,#C,#D,#E,#F,#G,#H,#I,#J').hide(); 
}); 

$('.nextbuttonB').hoverIntent(function() { 
$('#B').fadeIn("slow");$('#A,#C,#D,#E,#F,#G,#H,#I,#J').fadeOut(); 
}, function() { 
$('#A,#C,#D,#E,#F,#G,#H,#I,#J').hide(); 
}); 

-------etc---------- 

那么是什么做的是在鼠标悬停按钮添加图像,然后使用他们hoverintent打开具有绝对定位的元素师,一个大型的菜单非凡如果你愿意。 nextHide CSS只是显示:none; cursor:pointer;和名为A,B的HTML div ... 男人,我爱这个jQuery的东西。

谢谢elclarenrs,很棒的链接。