2d-css-matrix-parse 中文文档教程
2d-css-matrix-parse
将 css 变换矩阵转换为 6 个值的二维数组(3x3 矩阵)。
Function parse
parse
函数采用矩阵字符串表示形式,如 matrix(1.1, 0, 0, 1.1, 0, 0)
并将其解析为浮点数组。
var matrixTransform = require('./index.js');
var matrix = "matrix(1.1, 0, 0, 1.1, 0, 0)";
matrixTransform.parse(matrix);
// -> [1.1, 0, 0, 1.1, 0, 0]
Function fromElement
fromElement
函数试图帮助您获取转换字符串矩阵表示,并让您传递 HTML 元素本身而不是字符串。
var matrixTransform = require('./index.js');
var element = document.createElement('div');
element.style.transform = "scale(1.5)";
document.body.appendChild(element);
matrixTransform.fromElement(element);
// -> [1.5,0,0,1.5,0,0]
重要提示:
如果转换不是矩阵格式也没关系,在上面的例子中我们设置element
值scale
而不是当前矩阵。
Usage
matrixTransform.parse(string)
它采用字符串矩阵表示形式并为您提供一个数组。
matrixTransform.fromElement(HtmlElement)
它需要一个 Html 元素,并为您提供一个带有元素转换的数组。
License
MIT,详见LICENSE.md。
2d-css-matrix-parse
Converts css transform matrix to an 2D array of 6 values(3x3 matrix).
Function parse
The parse
function takes a matrix string representation like matrix(1.1, 0, 0, 1.1, 0, 0)
and parse it to an array of floats.
var matrixTransform = require('./index.js');
var matrix = "matrix(1.1, 0, 0, 1.1, 0, 0)";
matrixTransform.parse(matrix);
// -> [1.1, 0, 0, 1.1, 0, 0]
Function fromElement
The fromElement
function tries to help you to get the transform string matrix representation and let you pass instead of the string the HTML element itself.
var matrixTransform = require('./index.js');
var element = document.createElement('div');
element.style.transform = "scale(1.5)";
document.body.appendChild(element);
matrixTransform.fromElement(element);
// -> [1.5,0,0,1.5,0,0]
Important Note:
Doesn't matter if the transform is not formatted as a matrix, in the above example we are setting to element
the value scale
instead of the current matrix.
Usage
matrixTransform.parse(string)
It takes a string matrix representation and gives you an array.
matrixTransform.fromElement(HtmlElement)
It takes an Html Element and gives you an array with the element transformation.
License
MIT, see LICENSE.md for details.