How can I loop an animation continuously in jQuery?

前端 未结 9 1217
长情又很酷
长情又很酷 2020-12-01 14:52

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:



        
相关标签:
9条回答
  • 2020-12-01 15:11

    Following should work.

    $(document).ready(function(){
        animateTheBox();
    }); 
    
    function animateTheBox() {
        $(".boxtext").animate({bottom:"600px"}, 50000, animateTheBox);
    }
    
    0 讨论(0)
  • 2020-12-01 15:16

    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);
    
    0 讨论(0)
  • 2020-12-01 15:17

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

    0 讨论(0)
  • 2020-12-01 15:18

    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.

    0 讨论(0)
  • 2020-12-01 15:20
    <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

    0 讨论(0)
  • 2020-12-01 15:22
    <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>  
    
    0 讨论(0)
提交回复
热议问题