14

I need to know how to infinitely loop this animation. It is a text scroll animation and I need it to repeat after it's finished.

Here is the jQuery:

<script type="text/javascript"  src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript"> 
    $(document).ready(function(){
        $(".boxtext").ready(function(){
            $(".boxtext").animate({bottom:"600px"},50000);
        });
    });
</script>  

Here is the CSS for ".boxtext"

.boxtext {
    position:absolute;
    bottom:-300px;
    width:470px;
    height:310px;
    font-size:25px;
    font-family:trajan pro;
    color:white;
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
user830593
  • 221
  • 1
  • 6
  • 13
  • 3
    You might want to be careful using fonts that not everyone, and given the name, or even most won't have. – CassOnMars Jul 20 '11 at 19:21
  • Check my answer http://stackoverflow.com/questions/14530718/jquery-restart-animation-after-it-stops/14530823#comment20264568_14530823 it's the same story. – M K Jan 25 '13 at 22:51

9 Answers9

14

Make it a function and have it call itself as a callback:

$(document).ready(function(){
    scroll();
}

function scroll() {
    $(".boxtext").css("bottom", "-300px");
    $(".boxtext").animate({bottom:"600px"}, 50000, scroll);
}

Keep in mind, this won't be very fluid.

EDIT: I wasn't thinking earlier. My mistake.

CassOnMars
  • 6,153
  • 2
  • 32
  • 47
4

Following should work.

$(document).ready(function(){
    animateTheBox();
}); 

function animateTheBox() {
    $(".boxtext").animate({bottom:"600px"}, 50000, animateTheBox);
}
Yiğit Yener
  • 5,796
  • 1
  • 23
  • 26
3

probably the simplest solution.

var movement1 = function(speed){
  $(".mydiv").animate({"top": "100px"}, speed,function(){
      movement2(speed)
  });
}


var movement2 = function(speed){
  $(".mydiv").animate({"top": "120px"}, speed,function(){
      movement1(speed)
  });
}

  movement1(1000);

this is eventually call each other infinitely.

saad arshad
  • 259
  • 1
  • 10
1
<script type="text/javascript"  src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript"> 

$(function () {    
        move();
        });
function move(){
     $(".boxtext").ready(function(){
     $(".boxtext").animate({bottom:"600px"},50000,function(){
         $(".boxtext").css({"bottom":0}, move););

 });move();
 });
 </script>  
Ken White
  • 123,280
  • 14
  • 225
  • 444
Felipe
  • 11
  • 1
0

Please try this for continuous loop animation on hover.

function loopl(){
    $('.mCSB_container').animate({ "left": "+=80px" }, "800", 'linear', loopl  );
    }    

function loopr(){
        $('.mCSB_container').animate({ "left": "-=80px" }, "800", 'linear', loopr  );
    }
    function stop(){
        $('.mCSB_container').stop();
    }
    $( "#left" ).hover(loopl, stop);
    $( "#right" ).hover(loopr, stop);
Ganpat Kakar
  • 153
  • 1
  • 11
0
yourloop = setInterval(function() {
  // tasks
}, timeInMilliseconds );

Enjoy!

jantocv
  • 21
  • 2
  • 3
0

Use setInterval. This way you can repeat a function infinitely after a certain interval, such as every second.

Headache
  • 239
  • 2
  • 8
0
<script type="text/javascript"> 
var e = document.getElementByClassName('boxtext')[0].style.bottom;
function reset(){
if(e === "599px"){e === 0 + "px"}
else{b += 1000}
}
setInterval(reset(),1);

$(document).ready(function(){
    $(".boxtext").ready(function(){
        $(".boxtext").animate({bottom:"600px"},b);
    });
});

</script>  

idont no but i think should have used javascript

-2

Like this:

<script>
$(document).ready(function()
{
    $(window).load(function()
    {
        var a="#bijin"
        var x=1000
        var y=1000

        for (var i=1 ; i<=100000 ; i++){
            $(a).slideUp(x).slideDown(y);  
        }
    });
});

</script>

Example: http://www.hpcreating.com/effect/jquery2/slide4.html

SeinopSys
  • 8,787
  • 10
  • 62
  • 110
uedaka
  • 29
  • 1
  • 5
    -1 You're launching immediately into a one-hundred-thousand iteration loop and queueing up one hundred thousand animations. This is wasteful to the extreme. – doppelgreener Mar 12 '13 at 01:38
  • Same as @dopplegreener said and it doesn't even continue infinitely but 100000 iterations. Heavy on the performance side and doesn't solve the problem. – Stephen Tvedt Oct 01 '15 at 20:56