user900652
user900652

Reputation: 15

setInterval change background div

i have code

  function smena(){     
     $('.wrapper').animate({opacity:0},2500,function(){
           setTimeout ($('.wrapper').animate({opacity:1},2500),5000)
      });
   }
   $(document).ready(function(){

       setInterval('smena();',10000);   
  });

why me animaation jump? i want just change bg for my div "wrapper".

Upvotes: 0

Views: 755

Answers (1)

Steve Elliott
Steve Elliott

Reputation: 659

Basically you're not passing the functions around correctly for setTimeout. You're actually passing the result of "$('.wrapper').animate({opacity:1},2500)" to the setTimeout, not the action itself. This is probably what you want:

  function smena(){     
     $('.wrapper').animate({opacity:0},2500,function(){
           setTimeout (function() {
             $('.wrapper').animate({opacity:1},2500)
           },5000)
      });
  }
  $(document).ready(function() {
       setInterval(smena, 10000);   
  });

Upvotes: 2

Related Questions