Home >Web Front-end >HTML Tutorial >Deformation and animation in css3 (1)_html/css_WEB-ITnose
Several properties of CSS3 animation: transformation, transition and animation.
First introduce the transform deformation.
Transform English meaning: change, deformation.
Transform in CSS3 includes the following types: rotation, skew, scale, translate and matrix deformation.
Syntax:
transform : none | <transform-function> [ <transform-function> ]* transform: rotate | scale | skew | translate |matrix;
none is the default value and no transformation is performed.
51a72c16a181454beb1335050c004065: Indicates one or more transformation functions, is separated by spaces . You can perform multiple attribute operations of transform on an element at the same time, such as using rotate, scale and translate at the same time.
rotate(<rotate-angle> [<cx> <cy>])skewX(<skew-angle>)skewY(<skew-angle>)scale(<sx> [<sy>])translate(<tx> [<ty>])matrix(<a> <b> <c> <d> <e> <f>)1. Rotate rotate
rotate(0c0cb308ee3d2ee3281772bfc9b806c2): Specify a 2D rotation (2D rotation) for the element through the specified angle parameter, which requires transform first -Definition of origin attribute.
Transform-origin defines the base point of rotation, where angle refers to the selection angle, positive clockwise rotation, negative counterclockwise rotation.
2. translate translationThe translate() function can move elements from their original positions without affecting any web components on the x and y axes, similar to position:relative.
translate() has three situations:
Note: The base point of translate movement defaults to the center point of the element, and the base point can be changed according to transform-origin.
If the second value is not set, it defaults to 0.
is equivalent to the abbreviation of translate(x,0,), and the base point is the center point of the element.
is equivalent to the abbreviation of translate(0,y), and the base point is the element in the center.
3. Scale scalingScale scaling is very similar to translate movement, and there are three situations.
Zoom center point: that is, the center position of the element
Base: Zoom can be reduced or enlarged; the scaling base is 1, greater than 1 to enlarge, less than 1 to reduce.
Note: If the second parameter is not provided, it will take the same value as the first one.
Scale can take negative values. Negative values will cause the element to flip and scale.
<style> div { width: 100px; height: 100px; border-top: 1px dotted orange; border-right: 1px solid red; border-bottom: 1px solid pink; border-left: 1px solid green; text-align: center; line-height: 100px; color: red; font-size: 15px; transform: scale(-1.5); margin: 0 auto; margin-top: 50px;}</style><div>Scale(-1.5)</div>
4. Skew shear
There are three cases of skew like translate and scale.
That is, the x-axis and y-axis are twisted and deformed according to a certain angle value at the same time.
If the second parameter is not provided, the value is 0, that is, there is no bevel on the y-axis.
5. Matrix
matrix(d80b5def5ed1be6e26d91c2709f14170, d80b5def5ed1be6e26d91c2709f14170, d80b5def5ed1be6e26d91c2709f14170, d80b5def5ed1be6e26d91c2709f14170, d80b5def5ed1be6e26d91c2709f14170, d80b5def5ed1be6e26d91c2709f14170): Specifying a 2D transformation in the form of a six-value (a, b, c, d, e, f) transformation matrix is equivalent to directly applying a [a, b, c, d, e, f] transformation matrix. Just reposition elements based on horizontal and vertical directions.
SVG, css3, and html5 canvas all have matrix transformations. Let’s talk about them briefly.
After rendering an element, you can get a bitmap, and then transform each point on this bitmap to get a new bitmap, thus generating translation, scaling, rotation, shear and Mirror reflection light effect.
2D matrix transformation provides 6 parameters a, b, c, d, e, f. The basic formula is:
Among them, x and y are the elements The starting coordinates, x' and y' are the new coordinates obtained after matrix transformation.
Note: The six parameters a, b, c, d, e, and f in the transformation matrix are arranged vertically.
x'=ax+cy+ey'=bx+dy+f
x'=ax cy e, we set a=1,c=0, then x'=x e,
y'=bx dy f, similarly assuming b=0, d=1, then y'=y f.
This is translate(e,f).
So translate(e,f) is the simplified transformation matrix matrix(1,0,0,1,e,f),
(x,y) translation (tx, ty), which means that a matrix transformation of [1 0 0 1 tx, ty] is made.
x'=ax cy e, we set c=0, e=0, then x'=ax,
y'= bx dy f, we assume b=0, f=0, then y'=dy.
This is scale(a,d).
So scale(a,d) is the simplified transformation matrix matrix(a,0,0,d,0,0).
(x,y) scaling (sx,sy) means doing a matrix transformation of [sx 0 0 sy 0 0].
rotate(a deg) is equivalent to [cons(a) sin(a) -sin(a) cons(a) 0 0] matrix transformation.
skewX(a deg) is equivalent to the matrix transformation of [1 0 tan(a) 1 0 0].
skewY(a deg) is equivalent to the matrix transformation of [1 tan(a) 0 1 0 0].
So Matrix is a combination of all 2D effects.
6. transform-originAs mentioned earlier, the default base point of an element is its center position, and transform-origin can be used to change its base point.
Use:
transform-origin(x,y): used to set the base point (reference point) of the element. The default point is the center point of the element. The values of x and y can be percentages, em, px, where x can also be left, center, right, and y can be top, center, bottom, which is the same as background-position.
7. Resource links
Transformation matrices needed in front-end development
CSS3: Mathematical principles behind transform and transition [winter]
CSS3 2D Transform
w3c css3-2d-transforms
w3c RotationDefined
w3 document, about coordinate system and matrix transformation properties
w3 document, 3D transformation matrix in SVG
w3 document, 3D transformation matrix in CSS 3
Transform-style and Perspective properties