I am currently working on a CMS project to create perspective objects using CSS transform
properties (scale, rotate, translate...) in 3d: XYZ.
When an object is created it has these characteristics in its matrix3d(-16 values-) returned by window.getComputedStyle(element) -> style['transform']
The next step is to create animations: through a set of input[range]
, the user can modify these objects' characteristics and get their final state once the animation is finished.
It works very well. The question now is to create the complete dynamic CSS system, object by object.
I have its matrix1 (initial matrix3d) and its matrix2 (final matrix3d). By executing
@keyframes anim {
from { transform: matrix1 }
to { transform: matrix2; }
}
document.getElementById('object').style.animation = 'anim 2s linear';
it should work on its own... The prob is to create the CSS instruction. Using:
document.styleSheets[0].insertRule('
@keyframes anim {
from { transform: matrix1 }
to { transform: matrix2; }
}'
);
works well but once it's created in the main CSS file, if user modifies the matrix2 I can't rewrite the same instruction twice...
My idea is to create a CSS file for each objet on the server then import it with JS: if user is satisfied I keep it, and if not I remove it and create a new one with its new matrix2.
the advantage is that I can keep the word 'anim' without risking conflict between objects since each will call its own CSS (i.e 'object1.css').
Is this the best way to proceed or do you recommend another one?
Another question: despite my research I can't find what the 16 values of matrix3d correspond to. Translate XYZ is in [12], [13], [14] but I don't have them all. If you know a more explicit resource than https://developer.mozilla.org/fr/docs/Web/CSS/transform-function/matrix3d() it may help.