CSS3 webkitAnimationEnd event ordering -


i'm new stackoverflow , relatively new html5 programming. i'm writing (for safari, primarily) logic driven events fired out when webkit animations complete. if start number of animations of same length simultaneously, need idea of order can expect completion events fire. example:

<!doctype html> <html> <head>     <style>     @-webkit-keyframes slideright {         { left: 0; }         { left: 100px; }     }     </style> </head> <body>     <script type="text/javascript">      var square = function(ypos, color){         var mydiv = document.createelement("div");         mydiv.style.width = "20px";         mydiv.style.height = "20px";         mydiv.style.top = ypos + "px";         mydiv.style.backgroundcolor = color;         mydiv.style.position = "absolute";          document.body.appendchild(mydiv);          var squareinterface = {              onanimend: function(event){                 console.log(mydiv.style.backgroundcolor + " square finished animating");             },              startanim: function(){                 mydiv.style.webkitanimationname = "slideright";                 mydiv.style.webkitanimationduration = "2s";                 mydiv.addeventlistener('webkitanimationend', this.onanimend);             }         }          return squareinterface;     }      var myredfoo = square(0, "red");     var mybluefoo = square(30, "blue");      myredfoo.startanim();     mybluefoo.startanim();     </script> </body> </html> 

so, i'm creating red square , blue square in javascript, , (in safari , chrome) kicking off animations move them right, , print console when they're done. blue square first it's finished animating. playing around seems have nothing order in animations started, or positions of squares, order in they're created. "simultaneous" event callbacks seem occur on created element first, followed older elements.

my question can rely on behaviour? guaranteed in standards, or change depending on browser, or phase of moon? if event order can't guaranteed, strategies recommend coping that?

i can system dependent. i'm using osx lion, , in both chrome , safari "red" event logged before "blue" one.

if want hack out can more confident in timings, such:

function startredfoo(){ myredfoo.startanim() }; mybluefoo.startanim(); settimeout(startredfoo, 10); //ten small can go. 

you think able set timeout function myredfoo.startanim prevents messages being logged.

i can still imagine potential timing issues though, it's not fool proof.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -