开发者

Change animation speed with jQuery

开发者 https://www.devze.com 2023-03-04 16:42 出处:网络
$(\"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
$("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

精彩评论

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