對不起,如果這是一個noob問題,但有沒有辦法將這些mouseenter/mouseleave事件結合起來?jQuery - 幫助結合多個mouseenter/mouseleave事件
$('.home').mouseenter(function(){
$('#display_home:hidden').fadeIn(400);
}).mouseleave(function(){
$('#display_home').hide()
});
$('.about').mouseenter(function(){
$('#display_about:hidden').fadeIn(400);
}).mouseleave(function(){
$('#display_about').hide();
});
$('.contact').mouseenter(function(){
$('#display_contact:hidden').fadeIn(400);
}).mouseleave(function(){
$('#display_contact').hide();
});
$('.services').mouseenter(function(){
$('#display_services:hidden').fadeIn(400);
}).mouseleave(function(){
$('#display_services').hide();
});
我試過各種程序員的各種方法。我試圖隱藏/顯示多個div,通過將dl類鏈接到由mouseenter
函數關聯的li類來獨立地進行隱藏/顯示,但我是jQuery的新手,似乎無法找到解決方案。我知道必須有更乾淨的方式來做到這一點,但我還沒有找到。任何幫助將不勝感激!
感謝
HTML:
<div id="right_nav">
<div id='display_home'><img src="images/gallery/home.png" width="605" height="300" /></div>
<div id='display_about'><img src="images/gallery/about us.png" width="605" height="300" /></div>
<div id='display_contact'><img src="images/gallery/Contact Us.png" width="605" height="300" /></div>
<div id='display_services'><img src="images/gallery/Services.png" width="605" height="300" /></div>
</div>
<div id="thumb">
<ul>
<li class="home"><img src="images/gallery/thumb/home.png" width="82" height="23" /></li>
<li class="about"><img src="images/gallery/thumb/about us.png" width="130" height="24" /></li>
<li class="contact"><img src="images/gallery/thumb/Contact Us.png" width="150" height="23" /></li>
<li class="services"><img src="images/gallery/thumb/Services.png" width="113" height="24" /></li>
</ul>
</div>
+1 for'hover()' –
我會改變$('。home,.about,.contact,,services')。hover(function(){'to'$('li',$ (「#thumb」)。hover(function(){'這樣當名稱改變或添加新菜單條目時無關緊要 –
@Björn:tnx更新 – PeeHaa