0

How can i get the currently applied CSS property-identifiers from an element (excluding the value)?

Or rather: How to get the elements e.g. translate, skew, rotate or rect? I don't mean the complete returned string like: rect(300px 0px 0px 300px). I mean just the property-identifiers...

I'm not a really familiar with RegExp but maybe can that do the trick?

So for better interpretation purposes:

I need to check for that, change some values (via matrix-array) and reapply them back to the element again.

// http://stackoverflow.com/a/5968313/1250044
function matrixToArray(matrix) {
    return matrix.substr(7, matrix.length - 8).split(', ');
}

$("#foo").css("clip","rect(300px 0px 0px 300px)");
var matrix = matrixToArray($("#foo").css("clip"));

                              // If `#foo` has something else
                              // applied than `clip`, then
                    --- ˅ --- // is that not really dynamically
$("#bar").css("clip", "rect(" + matrix[0] + matrix[1] + matrix[2] + matrix[3] + ")");
yckart
  • 32,460
  • 9
  • 122
  • 129

3 Answers3

0

You can use window.getComputedStyle():

// your elemenet
var el;

// get the transformations applied:
var transform = window.getComputedStyle( el ).transform;

This will, however, get you a matrix in most of the cases and not the individual transformations applied.

Sirko
  • 72,589
  • 19
  • 149
  • 183
0

E.g.,

$(ele).css('rotate')

To detect, check if the return length > 0

$(ele).css('rotate').length
taox
  • 55
  • 5
0

Got it...

Quite simple:

var getIdentifier = function(str) {
    return str.split('(')[0];
};

getIdentifier( 'rect(300px 0px 0px 300px)' ) // => 'rect'

yckart
  • 32,460
  • 9
  • 122
  • 129