jquery element change with time interval

Asked

Viewed 163 times

0

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

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

I wanted it to run until it was clicked

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

Barter

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

barter

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

barter

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

That is, you keep switching between the three until you click one of them

  • Pow, little question went blank even

1 answer

1


I’m not sure I understand your problem, but I think this 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 code working: https://jsfiddle.net/yoz2t3aL/1/

  • That’s why I gave up on answering this question: I couldn’t quite understand what he wants

Browser other questions tagged

You are not signed in. Login or sign up in order to post.