Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's an attempt at solving the problem with Javascript: <a href="http://jsfiddle.net/eGDP7/">http://jsfiddle.net/eGDP7/</a> </p> <p>I'm using a data attribute on the html to list the classes with transforms that we want to apply:</p> <pre><code>&lt;div class="compoundtransform" data-transformations="scaletrans2, rotatetrans1"&gt;Test subject&lt;/div&gt; </code></pre> <p>I iterate through the classes and find out what css rules they represent:</p> <pre><code>function getCSSRulesForClass( selector ) { var sheets = document.styleSheets; var cssRules = []; for (var i = 0; i&lt;sheets.length; ++i) { var sheet = sheets[i]; if( !sheet.cssRules ) { continue; } for (var j = 0; j &lt; sheet.cssRules.length; ++j ) { var rule = sheet.cssRules[j]; if (rule.selectorText &amp;&amp; rule.selectorText.split(',').indexOf(selector) !== -1) { var styles = rule.style; for( var k = 0; k&lt;styles.length; ++k ) { var style = styles[k]; cssRules.push( { property: style, value: styles[style] } ); } } } } return cssRules; } </code></pre> <p>I find any transforms and apply the transforms to a matrix:</p> <pre><code>function convertTransformToMatrix( source, transformValue ) { var values = transformValue.split(") "); // split into array if multiple values var matrix = cloneObject( source ); for ( var i = 0; i&lt;values.length; ++i ) { var value = values[i]; if( isRotate( value ) ) { var rotationValue = cssRotationToRadians( value ); var cosValue = Math.cos( rotationValue ); var sinValue = Math.sin( rotationValue ); var a = matrix.a; var b = matrix.b; var c = matrix.c; var d = matrix.d; var tx = matrix.tx; var ty = matrix.ty; matrix.a = a*cosValue - b*sinValue; matrix.b = a*sinValue + b*cosValue; matrix.c = c*cosValue - d*sinValue; matrix.d = c*sinValue + d*cosValue; matrix.tx = tx*cosValue - ty*sinValue; matrix.ty = tx*sinValue + ty*cosValue; } else if ( isScale( value ) ) { var scale = cssScaleToObject( value ); matrix.a *= scale.x; matrix.b *= scale.y; matrix.c *= scale.x; matrix.d *= scale.y; matrix.tx *= scale.x; matrix.ty *= scale.y; } else if ( isTranslate( value ) ) { var translate = cssTranslateToObject( value ); matrix.tx += translate.x; matrix.ty += translate.y; } } return matrix; } </code></pre> <p>And I, finally, apply that matrix to the node as a transform.</p> <p>Currently:</p> <ul> <li>The code is a bit messy</li> <li>The CSS parsing is limited to scale(x,y), translate(x,y), and rotate with degree or radian values </li> <li>And it would only work with the webkit vendor prefix</li> </ul> <p>I might tidy it up and turn it into a utility if useful to anyone.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload