I have made a CSS3 ajax loader using this code. id is the location of the ajaxloader. This code works fine and the loader functions properly, however if the function is called twice, the Timeout's will cancel each other out because the timeout is assigned to a variable. Somehow, I want to make sure that this will never happen. Here is the javascript I am using
function ajaxloader(id) {
var i = $("#" + id + " .ajaxpieces").length;
var s = $("#" + id + " .ajaxpieces").filter(function() {
return ($(this).css('background-color') == "rgb(0, 128, 0)");
}).next();
if (s.length < 1) {
s = $("#" + id + " .ajaxpieces").first();
}
s.css('backgroundColor','green').siblings().css('backgroundColor','grey');
ajax_ii = setTimeout(function(){ajaxloader(id);},550);
}
function killloader() {
clearTimeout(ajax_ii);
}