javascript - Add transition to dynamic DOM element -


I'm trying to add transition to the div element. Transitions have been successfully added to the previously added elements. When I add more divins by clicking on .container then this animation does not contain these new devices. How can I add transition to a dynamic device?

Below is my code

  var transition = 1; Var x = 0; Var left = 0; Drew ('white'); Var $ rect = $ ('. Rect'); Var $ Container = $ ('Container'); Var arr = ['red', 'green', 'black']; Var calculation = 0; $ ('Body') On ('click', function () {draw (arr [count]); count ++;}); Function init () {setInterval (onEachStep, 1000/60); } ACHEST () {x + = transition; Left = left + infection; $ Rect.css ('left', left + 'px'); If (x & gt; $ container.outwidth () - $ rect.outerWidth ()) {transit = -10; } If (x> <0) {transit = 1; }} Function draw (color) {var rect = $ ('& lt; div / & gt;', {'class': 'rect'}); Rect.css ('background', color); Rect.appendTo ('container.'); } Init ();  
  & lt; Script src = "https://ajax.googleapis.com/ajax/libs/JQuery/1.1.0.0/jquery.min.js" & gt; & Lt; / Script & gt; 

You need to store left, X and transition for each rectangle. Having one transition for the left, X and all will mean that they will be in one place at any point at all times.

  Draw ('white'); Var $ Container = $ ('Container'); Var arr = ['red', 'green', 'black']; Var calculation = 0; $ ('Body') Function init () {setInterval (onEachStep, 1000/60);} on the function ('click', function () (draw (ARR [count% arr.length]); count; For $ rect = $ ('.rect'); (var i = 0; i  $ container.outwidth () - $ (right) Overvidth ()) {therect.transition = -10;} If (true. X  
  & lt; script src = "https://ajax.googleapis.com/ajax/libs/JQuery/1.1.0.0/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Div class = "container" & gt; & Lt; / Div & gt;  


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -