Jquery animation repeating code

烂漫一生 提交于 2019-12-08 08:54:17

问题


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!


回答1:


           $(document).ready( function() {


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

           animate();

           });



回答2:


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.



来源:https://stackoverflow.com/questions/5311972/jquery-animation-repeating-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!