2011-05-08 86 views
2
$("a").hover(function(){ 
    $(this).animate({left: '-500px'}, 'slow'); 
); 

我使用此代码来为链接的位置设置动画。我用slow动画速度将它移动到左边角落。使用jQuery更改动画速度

我如何改变这个动画的速度fast,点击链接时?

我们应该:

  • slow动画当链接徘徊。
  • fast被点击时它。

问题是,当我们尝试点击链接时,链接可能已经生成动画。你怎么看?

谢谢。

+0

您可以指定的时间间隔作为第二个参数...这会照顾 – kobe 2011-05-08 17:47:53

回答

5
$("a").hover(function(){ 
    $(this).animate({left: '-500px'}, 'slow'); 
).click(function() { 
    $(this).dequeue().animate({left: '-500px'}, 'fast'); 
}); 
0

你可以尝试:

$("a").click(function(){ 
    $(this).stop(true).animate({left: '-500px'}, 'fast'); 
); 

(未测试)

0

这可能会实现,利用stop()已经停止任何动画运行。

$("a").click(function(){ 
    $(this).stop() 
    $(this).animate({left: '-500px'}, 'fast'); 
);