How to 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 get it. You only need Div. style. Left = '100px 'to set it. Very simple.

But css3 is coming.

For example:

<Div style = "-WebKit-transform: translate (20px,-20px)"> </div>

What should I do? Scared...

The setting is simple:
Div. style. webkittransform = 'translate (20px,-20px) 'follow the camper style.

When obtaining:
Div. style. webkittransform is the string 'translate (20px,-20px )'
How can I obtain the desired 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

Search for the match
Div. webkittransform. Match (REG) // result [20,-20]
An array containing the x and y values is returned.

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 );

Various...

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.