2009-06-08 31 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});} 
);