2011-03-01 54 views
0

簡單問題的道歉我剛剛開始。 我有一個導航div和4個按鈕類div。在div中選擇一個div

我希望能夠改變背景類的相應按鈕DIV當鼠標懸停/輸入等

這是我的Jquery到目前爲止

<script> 
$(document).ready(function(){ 
    $("#nav").mouseenter(function(){ 
    $(this).stop(true,true).find(".button").fadeTo(200,0.5,function(){ 
    $("#nav").mouseleave(function(){ 
    $(this).stop(true,true).find(".button").fadeTo(200,1); 
    }); 
    }); 
    }); 
}); 
</script> 
+1

問題是什麼?你有什麼問題? – Ikke 2011-03-01 11:56:20

+1

在jsfiddle.com上設置你的代碼,發佈鏈接,我們可以建議一個更好的方法來做到這一點 – Jason 2011-03-01 11:59:04

+0

我的主要問題是在div中選擇一個div,然後在mouseEnter時淡入該選定div的css屬性。 – George 2011-03-01 12:17:27

回答

1

我想你可能希望這樣的:

<script> 
$(document).ready(function(){ 
    $("#nav .button").mouseenter(function(){ 
    $(this).stop(true,true).fadeTo(200,0.5,function(){ 
    $(this).mouseleave(function(){ 
    $(this).stop(true,true).fadeTo(200,1); 
    }); 
    }); 
    }); 
}); 
</script> 

我不知道這是什麼一樣,也做了測試,但問題是我想你想的事件處理程序添加到按鈕本身,而不是容器。是這樣嗎?

+0

謝謝Victor給了我想要的效果。 .mouseenter字符串顯示了我從現在開始如何操作。 – George 2011-03-01 12:16:22

0

試試這個:

$('#nav').find('.button').each(function(){ 
    $(this).mouseover(function(){ 
     $(this).attr('style', 'background:url(http://jsfiddle.net/favicon.gif) top left'); 
    }); 
    $(this).mouseout(function(){ 
     $(this).attr('style', 'background:none'); 
    }); 
}); 

你可以看到它在這裏工作 - http://jsfiddle.net/FDQXa/

+0

嗨亞歷克斯你可以使背景Gif淡入?我的主要問題是選擇divs內的div – George 2011-03-01 12:13:55