John the Painter
John the Painter

Reputation: 2615

Changing speed (duration) on animation/stop

Had a look around and couldn't find an answer. I need to add the duration of animation to this code:

$('a:has(.image-active)').hover(function() { 
    $('.image-active', this).stop().animate({"opacity": 1}); 
},function() { 
    $('.image-active', this).stop().animate({"opacity": 0}); 
});

However, I can't work out where to place the duration. Just now it fades in to 1 and fades out to 0 which must be the default for jQuery.

Upvotes: 0

Views: 808

Answers (4)

dku.rajkumar
dku.rajkumar

Reputation: 18588

First of all opacity should not be in quotes change "opacity" to opacity

.animate({opacity: 1},100);

refer here

Upvotes: 0

Anthony Grist
Anthony Grist

Reputation: 38345

The jquery API for the .animate() method is a great place to start. You can specify a duration (either as a millisecond value, or the 'fast' or 'slow' string) for the animation, after the properties. The default is 400, if I recall correctly.

Upvotes: 0

techfoobar
techfoobar

Reputation: 66693

Pass the duration as the second parameter to animate(), for ex:

.animate({"opacity": 1}, "fast");

or

.animate({"opacity": 1}, 3000);

Upvotes: 2

Blender
Blender

Reputation: 298532

.animate() has a parameters object:

.animate({"opacity": 1}, {duration: 100});

I like being verbose, but you could also pass the duration as a number:

.animate({"opacity": 1}, 100);

Read the documentation for more options. Look at the examples.

Upvotes: 1

Related Questions