• CSSTransforms IS NOT a jQuery plugin, but a patch for some of it's built-in methods (a plugin needs to be released later, to handle some advanced issues).
The transform CSS property is by definition a list of transformation functions. This is probably the most complex type of css property (not a primitive value and not even a value list). It is a combination of one or more (up to 11) different functions, each of witch can be used more than once. Also, the order DOES matter.
CSSTransforms is designed to be as simple to use, as possible. It attempts to provide a "native" support for those transform functions to jQuery. It is neither possible to make this simple, nor possible to support this in the jQuery way, so we have chosen different approach here. For the sake of functionality and simplicity, we do limit the transform property to a set of unique functions only. For example, if an element has a rotation and skew applied, setting a rotation will replace the existing one (in other words, each transform functions, can be used only once). This brings some limitations, but still covers 90% of use cases and allows us to make other useful things, like supporting a preparatory css properties and mixing them with the regular ones...
All of the CSS transformation function names have been made available for use as a CSS property names with the $.fn.css() method. Those are:
These can also be animated, but see the limitations bellow
Additionally the following are considered very useful and also supported:
In jQuery $.fn.css() is used to get or set a css property of the element. One specific thing to note is that when used as a getter, it is queering the computed style, so always returns a value (even is one is not specified by the developer).
We have patched it to support the css transform function names as css property names (plus some others :-) ):
Name | GET Returns | Identity | SET argument | Units | Can be relative | Can be animated |
---|---|---|---|---|---|---|
matrix | string like "matrix(1, 2, 3, 4, 5, 6)"* | "matrix(1, 0, 0, 1, 0, 0)"* | 6 float numbers as Array, or comma separated list | none* | Yes | No |
rotate | string like "rotate(30deg)" | "rotate(0deg)" | single float number as number, or string, or as array entry. | "deg" - optional | Yes | Yes |
scale | string like "scale(1, 2)" | "scale(1, 1)" | one or two float numbers as comma-separated list or array | none | Yes | No (use scaleX and scaleY instead) |
scaleX | string like "scaleX(1)" | "scaleX(1)" | single float number as number, or string, or as array entry. | none | Yes | Yes |
scaleY | string like "scaleY(2)" | "scaleY(1)" | single float number as number, or string, or as array entry. | none | Yes | Yes |
skew | string like "skew(10deg, 20deg)" | "skew(0deg, 0deg)" | one or two float numbers as comma-separated list or array | "deg" - optional | Yes | No (use skewX and skewY instead) |
skewX | string like "skewX(10deg)" | "skewX(0deg)" | single float number as number, or string, or as array entry. | "deg" - optional | Yes | Yes |
skewY | string like "skewY(20deg)" | "skewY(0deg)" | single float number as number, or string, or as array entry. | "deg" - optional | Yes | Yes |
translate | string like "translate(10px, 20px)" | "translate(0px, 0px)" | one or two float numbers as comma-separated list or array | "px" - optional | Yes | No (use translateX and translateY instead) |
translateX | string like "translateX(10px)" | "translateX(0px)" | single float number as number, or string, or as array entry. | "px" - optional | Yes | Yes |
translateY | string like "translateY(20px)" | "translateY(0px)" | single float number as number, or string, or as array entry. | "px" - optional | Yes | Yes |
transform | string - space separated list of transform functions like "rotate(30deg) skewX(12deg)" | "none" | transform CSS (space separated list of transform functions) | N/A | No | No |
multiplied-matrix | string like "matrix(1, 2, 3, 4, 5, 6)"* | "matrix(1, 0, 0, 1, 0, 0)"* | N/A (read only) | N/A | N/A | N/A (read only) |
* - Gecko requires units to be used for translate arguments of the matrix. If used in Mozilla, the code will automatically append "px" to them, so matrices will look like "matrix(1, 0, 0, 1, 0px, 0px)".
Notes:
$("#theimage").css({ "rotate": 30 });$("#theimage").css({ "rotate": "+=30deg"});$("#theimage").css({ "rotate": -30 });$("#theimage").css({ "rotate": "-=30" });$("#theimage").css({ "rotate": ["+=15"] });$("#theimage").css({ "rotate": [10] });
$("#theimage").css({ "skew": 30 });$("#theimage").css({ "skew": "30, 10" });$("#theimage").css({ "skew": "30deg, 10" });$("#theimage").css({ "skew": ["30", "+=10"] });$("#theimage").css({ "skew": [20, 140] });$("#theimage").css({ "skew": "-=30" });$("#theimage").css({ "skew": [55] });
$("#theimage").css({ "skewX": 30 });$("#theimage").css({ "skewX": -30 });$("#theimage").css({ "skewX": "-=30" });$("#theimage").css({ "skewX": ["+=15"]});$("#theimage").css({ "skewX": [10] });
$("#theimage").css({ "skewY": 30 });$("#theimage").css({ "skewY": -30 });$("#theimage").css({ "skewY": "-=30" });$("#theimage").css({ "skewY": ["+=15"]});$("#theimage").css({ "skewY": [10] });
$("#theimage").css({ "scale": 2 });$("#theimage").css({ "scale": "2, 0.5" });$("#theimage").css({ "scale": "1.3, 1" });$("#theimage").css({ "scale": ["3", "+=0.10"] });$("#theimage").css({ "scale": "-=0.3" });$("#theimage").css({ "scale": [2] });
$("#theimage").css({ "scaleX": 3 });$("#theimage").css({ "scaleX": -0.3 });$("#theimage").css({ "scaleX": "-=0.3" });$("#theimage").css({ "scaleX": ["+=1.5"] });$("#theimage").css({ "scaleX": [2] });
$("#theimage").css({ "scaleY": 3 });$("#theimage").css({ "scaleY": -0.3 });$("#theimage").css({ "scaleY": "-=0.3" });$("#theimage").css({ "scaleY": ["+=1.5"] });$("#theimage").css({ "scaleY": [2] });
$("#theimage").css({ "translate": 200 });$("#theimage").css({ "translate": "120, 50" });$("#theimage").css({ "translate": "130px, 100" });$("#theimage").css({ "translate": ["30", "+=10px"] });$("#theimage").css({ "translate": "-=30px" });$("#theimage").css({ "translate": [120] });
$("#theimage").css({ "translateX": 30 });$("#theimage").css({ "translateX": -11 });$("#theimage").css({ "translateX": "-=30px" });$("#theimage").css({ "translateX": ["+=15"] });$("#theimage").css({ "translateX": [20] });
$("#theimage").css({ "translateY": 30 });$("#theimage").css({ "translateY": -11 });$("#theimage").css({ "translateY": "-=30px" });$("#theimage").css({ "translateY": ["+=15"] });$("#theimage").css({ "translateY": [20] });
$("#theimage").css({ "matrix": "3, 2, 1, 0, 20, -45" });$("#theimage").css({ "matrix": [1, 2, 3, "4", "-20px", 45] });$("#theimage").css({ "matrix": "-=0.3, +=0.2, +=0.1, -=0.5, +=2, +=5" });