Question

I have an object that gradually goes transparent and I would like to set a callback function when my object's opacity reaches a value of 0, so that I can reset the opacity and the position when completed.

Here is my code so far:

 var angle = 0;
 var reverseAngle = 0;
  setInterval(function(){
    angle+=3;
    reverseAngle-=3;
    $("#part1, #part3, #part5, #part7").rotate(angle);
    $("#part4, #part2").rotate(reverseAngle);
    $("#part9").animate({
      opacity: "-=0.1",
      top: "-=1"

    }, 800);
  },50);
Was it helpful?

Solution

You can add a callback function to the end of the animation.

$("#part9").animate({
      opacity: "-=0.1",
      top: "-=1"

    }, 800, function(){
        if($(this).css("opacity") <= 0){
           do stuff
        }
    }
);

I added <=, just in case

OTHER TIPS

jQuery's animate method allows for an onCompletion callback http://api.jquery.com/animate/ use that to alert you when the animation is complete.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top