Reduce the reflow and repaint and reflowrepaint of the browser

Source: Internet
Author: User

Reduce the reflow and repaint and reflowrepaint of the browser

1. Avoid frequent DOM operations on the document directly. If necessary, use the off-document method. The specific methods include but do not fully include the following:
(1) first Delete the element from the document, and then put the element back to its original position after modification.
(2) set the display of the element to "none". After the modification, change the display to the original value.
(3) If you need to create multiple DOM nodes, you can use DocumentFragment to add the document
2. Modify styles in a centralized manner
(1). Modify as few attributes as possible on the element style.
(2) try to modify the style by modifying the className
(3). Set the style value through the cssText attribute
3. cache Layout attribute values
For non-reference type values (numeric type) in the Layout attribute, if multiple accesses are required, you can store the values in the local variables for one access, and then use the local variables, this prevents rendering of the browser every time the attribute is read.
Var width = el. offsetWidth; var scrollLeft = el. scrollLeft;
4. Set the position of the element to absolute or fixed.
When the position of an element is static or relative, the element is in the DOM tree structure. When an operation on the element needs to be re-rendered, the browser renders the entire page. Setting the position of an element to absolute and fixed can separate the element from the DOM tree structure, the browser only needs to render the element and the element at the bottom of the element to shorten the rendering time of the browser to a certain extent, this is particularly worth considering in today's more and more Javascript animations.

Related Article

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.