2009-06-08 35 views

回答

0

您可以使用jQuery的animate做一些元素,其中包括定義應該多長時間動畫完成的持續時間參數。然後是需要一組函數的hover函數。因此,這是一般的想法:

$('div', '#nav_container').hover(function() { 
    // this gets called on hover 
    $(this).animate({width: 'XXXpx'}, 10000); // 10000 = 10 seconds   
}, function() { 
    // this gets called on mouseout 
    $(this).animate({width: 'XXXpx'}, 10000); // 10000 = 10 seconds 
}); 

編輯

至於你的評論,如果代碼是在<HEAD>,你需要用的代碼document.ready

$(document).ready(function() { 
    // put the code you tried here 
}); 
+0

我似乎無法得到這個工作。 Ive得到
<腳本類型= 「文本/ JavaScript的」 SRC = 「的jquery.js」> <腳本類型= 「文本/ JavaScript的」> $( '的div', '#nav_container')。懸停(函數(){(this).animate({width:'230px'},10000); // },function(){ $(this).animate({width:'203px'},10000) ; }); – 2009-06-08 18:11:54

2

事情是這樣的:

$('#nav_container div').hover(
    function(){$(this).find('img').animate({width:'100%'},{queue:false,duration:500});}, 
    function(){$(this).find('img').animate({width:'auto'},{queue:false,duration:500});} 
);