Do not use CSS expression for Cause Analysis

Source: Internet
Author: User

Use JavaScript expressions in CSS expressions. The CSS attribute is set based on the calculation result of the Javascript expression.
CSS expressions do not work in other browsers, so they are useful when setting ieseparately in cross-browser encoding.
CSS expressions are supported from ie5. Let's take a look at the following Code: Copy codeThe Code is as follows: Background-color: expression (new date (). gethours () % 2? "# F00": "# 00f ");

The above Code uses CSS expression to switch the background color every hour.
The problem with CSS expression is that its computing frequency is much higher than imagined. Not only when the page is displayed and scaled, but when the page is scrolling or even moving the mouse, it is re-computed. Add a counter to the CSS expression to track the computing frequency of the expression. You can easily move the mouse over 10000 times on the page.
One way to reduce the number of CSS expressions is to use a one-time expression. It assigns the result to the specified style attribute during the first run and uses this attribute to replace CSS expression.
If the style attribute must be dynamically changed within the page cycle, it is feasible to use the event handle instead of the CSS expression. If CSS expressions are required, remember that they must be calculated thousands of times and may affect the performance of your page. Do not make your users feel that opening your page will slow down.

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.