最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Change animation speed with jQuery - Stack Overflow

programmeradmin5浏览0评论
$("a").hover(function(){
    $(this).animate({left: '-500px'}, 'slow');
);

I use this code to 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');
);

I use this code to 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.

Share Improve this question edited May 8, 2011 at 17:50 James asked May 8, 2011 at 17:42 JamesJames 43.7k54 gold badges137 silver badges163 bronze badges 1
  • you can specify the time interval as a second argument...that will take care – kobe Commented May 8, 2011 at 17:47
Add a ment  | 

3 Answers 3

Reset to default 5
$("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)

  1. 暂无评论