jQuery Page Widget How to - Infinite loop on animate to move text








Question

We would like to know how to infinite loop on animate to move text.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-2.1.0.js'></script>
<style type='text/css'>
.slide-inner {<!-- w  w  w . j  a v a2s .c  o  m-->
  position: relative;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    var animate = function() {
      $(".slide-inner").animate({left: 100}, 1000, 'linear', function() {
        $(this).css('left', 1);
        animate();
      });
    }
    animate();
});
</script>
</head>
<body>
  <div class="slide-inner">Hi</div>
</body>
</html>

The code above is rendered as follows: