Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does animating the value of a CSS3 transform with javascript rule out hardware acceleration?

You can take advantage of hardware accelerated animations by setting an animation duration and setting the initial and final values of the CSS3 transform.

What if, instead of setting an animation duration and using keyframes, you animate the value of the desired CSS3 transform directly with JavaScript? Will you still be taking advantage of hardware acceleration, or is the hardware acceleration ruled out?

like image 458
trusktr Avatar asked Jan 09 '12 04:01

trusktr


People also ask

Can CSS animations can be hardware accelerated?

Hardware-Accelerated CSS on Desktop and Mobile BrowsersCSS animations, transforms and transitions are not automatically GPU accelerated, and instead execute from the browser's slower software rendering engine.

Is JavaScript good for animation?

JavaScript libraries are an extremely valuable tool for any web developer. Adding simple animations can easily be done with CSS, but as soon as it comes to more complex or advanced effects, JavaScript is the better tool.

Why is it generally no longer considered best practice to use jQuery for animation of CSS based equivalents are available?

Because — despite jQuery being tremendously powerful — it was never jQuery's design goal to be a performant animation engine: jQuery cannot avoid layout thrashing due to its codebase that serves many purposes beyond animation.

Can we do animation using only CSS without using JavaScript or jQuery?

CSS allows animation of HTML elements without using JavaScript or Flash!


1 Answers

It won't be hardware accelerated for webkit browsers unless you use transitions. Also, only 3d transforms are accelerated, so a quick way to ensure that the element is going to use the 3d rendering tree if it's avaliable is to add:

-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);

The reason transforms are quick by the way, is because by definition they don't affect any other elements - this means the browser doesn't need to repaint the whole window, just the part that's being transformed.

The old way of animating should really be considered obsolete, as it is much less efficient than transitions, and generally has a lower framerate, particularly on iOS.

like image 92
Rich Bradshaw Avatar answered Sep 29 '22 19:09

Rich Bradshaw