2012-04-24 52 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,很棒的鏈接。