jquery element change with time interval

0

I would like to make 3 or more animation blocks that, when clicking, would change according to the seconds, until someone clicks on one of the objects.

The function is working to click. Clicking switches between classes.

I wanted it to run until it was clicked

        var toggleClasscontentflow = function() {
        $('div.prime').click(function(){
            $(this).toggleClass('primeclicked');
  

Exchange

        });         
        $('div.second').click(function(){
            $(this).toggleClass('secondclicked');
  

Exchange

        });         
        $('div.third').click(function(){
            $(this).toggleClass('thirdclicked');
  

Exchange

        });};
    $(document).ready(toggleClasscontentflow);

That is, swap between the three until you click on one of them

    
asked by anonymous 31.05.2015 / 00:18

1 answer

1

I do not know if I understood your problem correctly, but I think it might help you:

$(function(){
   var interval;

   $('div').on('click', function(){
       $('div').removeClass();
       clearInterval(interval);

       interval = setInterval(function(){
           $('div').removeClass()
           for(var i = 1; i<= 3; i++){
               var number = 1 + Math.floor(Math.random() * 3);
               $('#div-'+i).addClass('clicked-'+number);
           }
       }, 1000);
   });
});

Link to see the code working: link

    
18.08.2015 / 20:24