How to loop the jquery animation?

function moveLeft(){ $('.someElement').css({left: '-1133px', transition: 'linear 20005ms'}); setInterval( reset, 20000 ); function reset() { $('.someElement').removeAttr('style'); setInterval( moveLeft, 0 ); } setInterval( reset, 20000 ); } moveLeft(); 

    1 answer 1

    One interval is enough.

    Updated .

     $(function() { function moveBlo() { var blo = $('.blo'); var int = setInterval(function() { if (parseInt(blo.css('left')) >= 400) { blo.css('left', '0'); } blo.animate({ left: '+=100' }, 200); }, 1000); } moveBlo(); }); 
     div.blo { width: 40px; height: 40px; position: relative; left: 0; top: 0; background-color: tomato; } 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="blo"></div> 

    • Not quite that, after one pass, all the styles of the element are removed and he again moves left from the initial position to the left one step, and so without stopping, infinitely. - Mikhail Umarov
    • @Misha Umarov updated. - Jean-Claude