开发者

Run function in infinite loop

开发者 https://www.devze.com 2023-01-01 07:19 出处:网络
I am creating a background color animation with jQuery and the color animation plugin http://plugins.jquery.com/project/color

I am creating a background color animation with jQuery and the color animation plugin http://plugins.jquery.com/project/color

How do I have a function stay in a loop repeating itself each time it has finished running? I tried this but it did not work :

 function colorLoop(){
开发者_如何转开发  $("#window")
     .animate({ backgroundColor: "orange" }, 11000)
  .animate({ backgroundColor: "violet" }, 1000)
  .animate({ backgroundColor: "red" }, 1000, colorLoop);
  };


You only created the function, but did not call it. Stick colorLoop(); between }; and });. Also, you really shouldn't be using jQuery for this kind of thing.


Use a loop, don't call a function, there's a good pulgin for Jquery:

Download Link

<script type= "text/javascript" src="jquery.timers-1.1.2.js" ></script>
    $("#window").everyTime(10, function(){
      $("#window")
        .animate({ backgroundColor: "orange" }, 11000)
        .animate({ backgroundColor: "violet" }, 1000)
        .animate({ backgroundColor: "red" }, 1000, 'swing');
      };
    });

This will be repeating the background animation...

0

精彩评论

暂无评论...
验证码 换一张
取 消