2013-10-12 73 views
1

如何設置動畫速度,使其以每秒2像素的速度移動?這裏我的塊的長度是310像素。我希望它以每秒2像素的速度移動。設置每秒2px的動畫速度?

$('#one').mouseenter(function(){ 
$('.alt0').animate({width: "310px"}, 150000, function(){ 
    $('#refresh-1').show(); 
}) 
$('#song-title1').show() 
}); 
$('#refresh-1').click(function(){ 
$('.alt0').width(0); 
$(this).hide(); 
}) 

回答

3

設置動畫持續時間310/2*1000(每像素時間半秒1000毫秒)和動畫寬鬆政策以「線性」。

$('.alt0').animate({width: "310px"}, 310/2*1000, "linear");

Code here

0

您可以使用此代碼對任何寬度:

$('.bar1').mouseenter(function(){ 
    $('.alt0').animate(
     {width: $(this).width()}, 
     ($(this).width())/2*1000,"linear", 
     function(){ 
      $("#button").show(); 
     }) 
}); 
$("#button").click(function(){ 
    $("#button").hide(); 
    $(".alt0").width(0); 
          }); 

JsFiddle DEMO