如何设置动画速度,使其以每秒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();
})
将动画持续时间设置为 310/2*1000
(每像素半秒乘以 1000 毫秒),并将动画缓动为"线性"。
$('.alt0').animate( {width: "310px"}, 310/2*1000, "linear" );
在这里编码
您可以将此代码用于任何宽度:
$('.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 演示