Do not use CSS expression 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's calculations.
CSS expression does not work in other browsers, so it is more useful to set the IE settings individually in Cross-browser encodings.
Support CSS Expression from IE5. Let's look at the following code:
Copy Code code as follows:

Background-color:expression (New Date ()). GetHours ()%2? "#F00": "#00F");

The code above is a CSS Expression that enables you to switch the background color once every one hours.
The problem with CSS expression is that it calculates more frequently than you think. Not only when the page is displayed and scaled, but when the page scrolls or even moves the mouse, it is recalculated. Add a counter to the CSS expression to track how often the expression is calculated. Moving the mouse around on the page can easily reach more than 10,000 times the amount of calculation.
A way to reduce the number of times a CSS Expression is calculated 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, it is a viable alternative to using the event handle instead of a CSS expression. 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.


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.