Effect of css attribute selection on animation performance-dehua. Chen

Source: Internet
Author: User
The Influence of css attribute selection on animation performance-dehua. Chen is now playing a higher proportion on mobile phones, and various cool pages are emerging. These special effects cannot be separated from css animation. When it comes to css animation, the mainstream situations are nothing more than these two categories: displacement and deformation. In the process of writing an animation special effect, how can we improve its performance? Of course, first of all, we need to understand the basic concepts, such as the working principle of browser rendering. I have read a few articles written by Daniel, I will not elaborate on it here. If you are interested, you can take a look. The purpose of this article is simply and roughly speaking, in fact, what css attributes should we use to draw an animation, which can effectively improve the performance of the browser in the rendering and rendering process.

Left and transform are used to translate the 500px shift to the right in 2 seconds. The Code is as follows:

Then, the following result is obtained in chrome. The first is left, and the second is transform:

Transform

Obviously, in the frame mode, we can see that left is lower than the number of transform frames, and the time consumed in rendering and drawing is far greater than transform. I believe you have come to a conclusion.
We use chrome's show paint rectangles to observe the differences between the rendering and the drawn areas during the animation process. The first is left, and the second is transform:

Transform

We can see that during the animation process written with left, the browser has been rendering. In contrast, when using transform, the animation is drawn only at the beginning and end. Therefore, for the animation performance, transform should be better. As for the reason, we need to introduce a concept that triggers the re-layout:

When we change some attributes, layout-related attributes will trigger re-layout, resulting in longer rendering and rendering time. Therefore, when writing an animation, we should avoid these attributes: width, height, margin, padding, border, display, top, right, bottom, left, position, float, overflow.
Attributes that do not start to re-layout include: transform (including translate, rotate, scale), color, and background.

Therefore, when writing css animations, we should give priority to the attributes that do not trigger the re-layout, so that the animation effects we present can be smoother.

Reprinted please indicate from: Ctrip Design Committee

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.