iphone - WebKit CSS transformations and animations in Javascript -


i'm working on iphone web application. starded playing webkit-transform , webkit-animation css rules. i've questions: example, there real advantage in using these instead of, say, jquery.animate(...)? resulting animations don't seem accelerated , fast. let's explain better: i've series of images have move on screen, gallery... set each image css rules this:

-webkit-transition-property: left, top, right, bottom, width; -webkit-transition-duration: 200ms; 

then change style.left , style.top of each element want move new coordinates. result not fast expected. fast more or less jquery (not fluid @ all). i've seen there -webkit-animation , -webkit-transform still don't understand how use them properly. first 1 lets me move things around, doesn't generate animation, use following code:

var trans = "translate(" + x + "px," + y + "px)"; element.style.webkittransform = trans; 

with element moves around, without animation. if create dynamically animation with:

var lastsheet = document.stylesheets[document.stylesheets.length - 1]; lastsheet.insertrule("@-webkit-keyframes "+ "animx" + "{ { top: "+oy+"px; left:"+ox+"px;} {top: " + y + "px; left: " + x + "px; } }",lastsheet.cssrules.length); element.style.webkitanimationname = "animx"; 

this way element move once, not fludly, , it's old position. repeating code doesn't lead anything.

what think, there real advantage in terms of fluidity of movement in using those? , if yes, how use them properly?

something should want, , runs quite smoothly in safari on iphone 4:

<style type='text/css'>      #element {          position: absolute;         top: 0px;         left: 0px;         -webkit-transition-property: top, left, bottom, right;         -webkit-transition-duration: 300ms;         -webkit-transition-timing-function: ease-in;      }  </style>  <script type='text/javascript'>      document.queryselector('#element').style.left = '300px';  </script> 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -