Reputation: 828
I've been reading a lot recent about optimizing CSS and JavaScript/jQuery for GPU performance, particularly on mobile devices, particularly where the CSS animation changes have a detrimental effect on a websites performance.
I've done some testing and I just can't tell if I've optimized my code correctly for performance.
The base transform animations are for either max-height
or the position
properties
I've put together a simple codepen to try and show where I am up to and what I am trying to achieve. http://codepen.io/onebitrocket/pen/jFrtf
I've checked the performance timeline in chrome, but I'm not sure if the result is as expected for optimized CSS and jQuery.
Would I see better performance using JavaScript and classList.toggle, instead of jQuery as in the demo, does jQuery prevent optimization of CSS animation?
I'm also seeing several paint events where the layer root it document.
Thanks
Upvotes: 0
Views: 146
Reputation: 18292
It is optimised. You're using 3d transforms for translation, which is quick. When the top box moves, the paiting over the links is due to the change in colour and the underline. The movement of the box happens on the GPU and shouldn't affect anything else.
However, animating a width
or height
property is a different thing. Those are layout
properties, so, when they change, the layout of the page changes and it needs to be repainted. In your case, there is nothing after the box, but if you put more elements, they would move up and down when you animate the box size.
Properties in CSS can be divided in three groups:
Of course, every browser is different and they (especially Chrome and Firefox) evolve very quickly, so they are being optimised all the time. What today is slow tomorrow can be quick. There may be cases where animating a property of the first group may be as fast as one of the last group, but as a general rule, it won't.
Upvotes: 1