Run function in infinite loop
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...
精彩评论