JS determines whether the browser supports a certain CSS3 attribute method, jscss3

Source: Internet
Author: User

JS determines whether the browser supports a certain CSS3 attribute method, jscss3

1. Introduction

The emergence of css3 makes the browser's performance more colorful, and the biggest impact of performance is animation. During daily animation writing, it is necessary to determine whether the browser supports it in advance, especially when writing a CSS3 animation library. For example, the animation-play-state of transition is only supported by some browsers.

2. Detection Method

The following method uses a script to determine whether the browser supports a certain CSS3 attribute:

/*** Determine whether the browser supports a certain CSS3 attribute * @ param {String} attribute name * @ return {Boolean} true/false * @ version 1.0 * @ author ydr. me * April 4, 2014 14:47:19 */function supportCss3 (style) {var prefix = ['webkit', 'moz', 'ms', 'O'], I, humpString = [], htmlStyle = document.doc umentElement. style, _ toHumb = function (string) {return string. replace (/-(\ w)/g, function ($0, $1) {return $1. toUpperCase () ;}) ;}; for (I in prefix) humpString. push (_ toHumb (prefix [I] + '-' + style); humpString. push (_ toHumb (style); for (I in humpString) if (humpString [I] in htmlStyle) return true; return false ;}

3. Usage

Alert (supportCss3 ('animation-play-state '));


Check whether the browser supports CSS3.

(3) Please refer to the following example: I advise you to use HTML, CSS and JavaScript. The following are the steps. 1) first create the following HTML <spanid = "check" rel = "Detect"> </span> 2) then write the following CSS # check {display: none; width: 0; height: 0; }# check [rel ^ = "D"] {display: block; width: 0; height: 0;} 3) the following is the JavaScripts detection script. Make sure that the following code is placed in the HTML file header. <Scripttype = "text/javascript"> varobj = document. getElementById ("check"); varfile = "special.css"; if (window. getComputedStyle) varstat = window. getComputedStyle (obj, null ). getPropertyValue ("display"); elseif (obj. currentStyle) varstat = obj. currentStyle. display; varcss3 = (stat = "block"); if (css3) alert ("CSS3Supported. "); elsealert (" CSS3notsupported. "); </script> I want to contribute div + css Volunteer: Jiang Xiaofei's comments are incorrect. [copyright description] the copyright to" computer "belongs to the author. You You can refer to your computer information for personal learning. All the Computer Information of kullie network is collected online for hobbies and uploaded by members, so that effective resources can be shared to users in a timely manner, however, due to the complexity of information sources, this site does not guarantee its accuracy and is only for reference. Teaching and personal learning and communication! It is strictly prohibited for any commercial purposes. This site is not responsible for your use! If your rights are violated, please let us know and we will delete it immediately after verification! Thank you.

Check whether the user's browser supports CSS3

Ghjkl; cvbnm, fghj rice cooker
 

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.