I am trying to create div boxes step by step and animate them several times at the click of a button. I have a startup code and everything is going well. It goes straight to the end, and then returns to its original place. This is basically what I'm doing, as well as a demo can be found here: http://jsfiddle.net/LSegC/1/
Now what I want to do is increase the number of animated DIVs one at a time (as of now) to 3 Divs, but then have an exponential increase in the total number of DIVs. Thus, the total number of animated DIVs will be 1, 2, 3, and then 4, 8, 16, etc.
Remember, my problem is not that the number is displayed inside the DIV, in fact, how many DIVS are created! So I want, for example, 8 DIVs, numbered from 1 to 8 animated. Hopefully now clear.
$(document).ready(function(){
$("button").click(function() {
var d = $(".t").fadeIn();
var speed = +$("#number1").val();
d.animate({left:'+=230px'}, speed);
d.animate({left:'+=230px'}, speed);
d.animate({top:'+=20px', backgroundColor: "#f09090", text:'12'}, speed/4, "swing", function() {
$('.span', this).fadeOut(100, function() {
$(this).text(function() {
return 'a' + $(this).text().replace('a', '');
}).fadeIn(100);
});
});
d.delay(1000).animate({left:'-=230px'}, speed);
d.animate({left:'-=230px'}, speed);
d.fadeOut().promise().done(function() {
d.last().after(function() {
var top = +$(this).css('top').replace('px', ''),
number = +$(this).data('number') + 1,
$clone = $(this).clone();
$clone.data('number', number).css('top', top + 20);
$clone.find('.span').text(number);
return $clone;
});
d.find('.span').text(function() {
return $(this).text().replace('a', '');
});
})
});