Multiple animations with .animate()
Hello,
today I was working on my new project and I noticed a problem using .animate() method.
For example:
I have something like:
- <div id="container">
- <div id="element1">...content...</div>
- <div id="element2">...content...</div>
- <div id="element3">...content...</div>
- etc.. // here is more elements
- </div>
And:
- $('#element1').animate({ left: "+=32", top: "+=32" }, 500);
- $('#element2').animate({ left: "+=32", top: "-=32" }, 500);
- $('#element3').animate({ left: "-=32", top: "+=32" }, 500);
- etc... // there is more animations created by loop
And it works perfectly. However, the main problem is that sometimes I need to add new elements to the container.
- str = "[some divs here]";
- document.getElementById("container").innerHTML += str;
Then, the animation stops. Why does it happen and how can I fix that?