N.Bankin
N.Bankin

Reputation: 1

Question about .stop() in jQuery !

I know that .stop() function is used to stop animation .. but where should I put it when I have this code:

$('#home').mouseover(function(){
    $('.subhome_icon').animate({
        "width":"5px",
        "opacity":"1.0"
    },1);
    $('.subhome_icon').animate({
        "height":"15px"
    },1000);
    $('.subhome_icon').animate({
        "width":"60px"
    },1000);
}).mouseout(function(){
    $('.subhome_icon').animate({
        "opacity" :"0.0"
    },1000);
});

And I want to stop the animation when I leave the icon with the mouse pointer ! I've wathced many jQuery videos but the examples are with one animation .. I've got 3 !?

Thanks you ! : )

Upvotes: 0

Views: 76

Answers (2)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 195992

You need to use

.mouseout(function(){ 
    $('.subhome_icon').stop(true).animate({ 
                            "opacity" :"0.0" },
                         1000); 
});

(notice the true argument passed to the .stop() method)

This clears the queued animations so it truly stops at the current state.

Upvotes: 1

James South
James South

Reputation: 10635

This should do it....

$('#home').mouseover(function(){ 
    $('.subhome_icon').animate({ "width":"5px", "opacity":"1.0" },1); 
    $('.subhome_icon').animate({ "height":"15px" },1000); 
    $('.subhome_icon').animate({ "width":"60px" },1000); })
.mouseout(function(){ 
    $('.subhome_icon').stop().animate({ "opacity" :"0.0" },1000); 
});

Upvotes: 2

Related Questions