Do not use CSS expression for reason analysis _ Experience Exchange

Source: Internet
Author: User
Use JavaScript expressions in CSS expression. CSS properties are set based on the results of the JavaScript expression calculations.
CSS expression does not work in other browsers, so it is useful to set it separately for IE in cross-browser encoding.
Support for CSS Expression starting from IE5. Let's look at the following code:
Copy the Code code as follows:
Background-color:expression (New Date ()). GetHours ()%2? "#F00": "#00F");

The above code uses CSS Expression to switch the background color at one-hour intervals.
The problem with CSS expression is that it can be calculated more often than you think. Not only when the page is displayed and scaled, it is recalculated when the page scrolls, or even when the mouse is moved. Add a counter to CSS expression to track how often expressions are calculated. Easily move the mouse in the page can be more than 10,000 times the amount of calculation.
A way to reduce the number of CSS expression calculations is to use a one-time expression that assigns the result to the specified style property at the first run and replaces the CSS expression with this property.
If the style attribute must change dynamically within the page cycle, using an event handle instead of a CSS expression is a viable option. If you must use CSS Expression, be sure to remember that they are counted thousands of times and may have an impact on the performance of your page. Do not let your users feel open your page, the machine will become very slow.
  • 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.