开发者

Change animation speed with jQuery

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

I use this code to 开发者_StackOverflow社区animate position of the link. I move it to the left corner with slow animation speed.

How do I change speed of this animation to fast, when link is clicked?

We should get:

  • slow animation when link is hovered.
  • fast when it is clicked.

The problem is, link can be already animated, when we try to click on it. What do you think?

Thanks.


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


You could try:

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

(Not tested)


This might work, using stop() to stop any animation already running.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜