Get and set CSS 3 attribute values in JS

Source: Internet
Author: User

Many css3 have added many attributes, and it is not as convenient as it was before during reading and writing. For example, <Div style =" Left: 100px "> </Div> If you only consider the line style, you only need Div. style. Left to obtain it. You only need Div. style. Left = '100px 'to set it. Very simple. But css3 is like: <Div style =" -WebKit-Transform: Translate(20px,-20px) "> </Div> what should I do? Scared... The setting is simple: div. style. webkittransform = 'translate (20px,-20px) 'follows the camper style. When getting the image: The Div. style. webkittransform value is the string 'translate (20px,-20px) '. How do I obtain the expected x and y values? No simple method was found for searching for half a day. Only string truncation or regular matching are supported. Write a regular expression to get the expected 20 and-20 Reg = /\-? [0-9] +/g match the negative number and number reg2 = /\-? [0-9] + \.? [0-9] */G may contain the decimal point and then match to search for the div. webkittransform. match (REG) // The result [20,-20] returns an array containing the x and y values. Likewise:-WebKit-Transform :   Skew ( 20deg , -50deg ) ;   /* Skew (skewed relative to the X axis and skewed relative to the Y axis )*/   -WebKit-Transform: Matrix(1,0.4,0,1,0,0); Various...
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.