0
votes

I have a div in my html code with this style:

-webkit-transform: translate(-360px, -360px) scale(1) translate(960px, 238.5px) translate(0px, 0px) scale(1);

the last value of scale goes from 1 to 2, and it is the zoom that I do with the scroll on the div.

I need to create in Javascript a conditional rule, in the situation that the scale is over 1.5, but how can I do it?

The other values could change, so I cannot rewrite the entire string...

something like:

var test = getElementById('div').style.webkitTransform.scale
if (test > 1.5) { };
1

1 Answers

0
votes

You can cut short with a simple regular expression:

var xform = document.getElementById('div').style.webkitTransform,
    match = xform.match(/scale\(([\-\d\.]+)\)$/);
if (m && m[1] > 1.5) {
    // ...
}

Of course you have to be sure that the transform property is in that exact format, but the conditional expression checks for it.