Jquery animation repeating code

2019-05-31 17:10发布

I have made code but I want it to be execute repeatedly till the user is on the page.

Here is my code---

                   $(document).ready(

                     function animate() {
                          $('div.lightining').stop().animate({
                            backgroundColor: '#789'
                          }, 1050, 'linear', function() { });
                     }

                     function () { $('div.lightining').cycle(animate()); }

                   );

I want that the script to repeat itself after getting completed. Does someone get any ideas of achieving this. Please help me out!

Thanks in advance!

2条回答
时光不老,我们不散
2楼-- · 2019-05-31 17:42

the code below will loop an animation continuously where

attribute is the attribute to animate

value the value to animate to

and duration the duration.

set these to whatever you want.

once the animation is complete the callback calls the animation again.

 $(document).ready(function(){

    animate();

});

function animate(){

    $(".lightning").animate({
        attribute:value
    },duration,function(){
        animate();
    });

}

not sure what you mean about the on the page part. you will have to clarify there. also if im correct, you cant animate background colour without a plugin.

查看更多
甜甜的少女心
3楼-- · 2019-05-31 17:47
           $(document).ready( function() {


             function animate() {
                  $('div.lightining').stop().animate({
                    backgroundColor: '#789'
                  }, 1050, 'linear', function() {  animate(); });
             }

           animate();

           });
查看更多
登录 后发表回答