将动画速度设置为每秒2像素?

时间:2013-10-12 11:36:29

标签: jquery animation

如何设置动画速度,使其以每秒2个像素的速度移动?这块块的长度是310像素。我希望它以每秒2个像素的速度移动。

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

2 个答案:

答案 0 :(得分:3)

将动画持续时间设置为310/2*1000(每像素半秒乘以1000毫秒),并将动画缓和为“线性”。

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

Code here

答案 1 :(得分: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