


A simple and crude explanation of the transform attribute in css3_html/css_WEB-ITnose
Please note in advance that the scope of this article is still limited to 2D transform.
I really love the transform attribute of CSS3. With this feature, various special effects can be easily achieved. To quote a lyric, "Spinning, jumping, I won't stop." Transform is so fashionable and willful. Of course, his willfulness is not only in terms of function, but also in terms of use. Let’s take a look at the introduction to the use of transform 2D on the W3C official website.
There are a lot of them, so let’s classify them first: one matrix, three translate, three scale, three skew, and one rotate. The three translates are divided into three types: XY, X, and Y. I drew a picture to roughly show the relationship between these operations.
Seeing this, some people may wonder why matrix is at the top of all other operations. In fact, other operations except matrix are an extension of matrix. What does it mean? ? The operations of translate, scale, skew and rotate are all used by people who do not understand the matrix principle. I am afraid that you do not understand the principle, so I have encapsulated several methods to allow you to use the matrix method conveniently. How to prove it? Interested children can check the style of the element (note: not the class rule, but the calculated style), or output the transform attribute of the element. See if you get uniform matrix results, similar to:
matrix(1, 0.466307658154999, 0, 1, 0, 0)
No more verbosity, since this is an operation, it all ends up matrix, so what is the relationship between them? If I use the knowledge of matrices to tell you how to calculate, it will not fit the title of this article, and there are already many such articles, so I will not show my shame and stick to the principle of the title: simple and crude explanation.
First let’s talk about translate, which means “transfer”. First, explain the syntax of translate:
transform:translate(25px,26px)
, which means shifting 25 pixels and 26 pixels to the right and down. Then we convert it to matrix syntax and look at this line of statement:
transform: matrix(1, 0, 0, 1, 25, 26);
Then there is scale. I am used to translating it into "zoom", so the translation also corresponds to its function: scaling component. Demonstrate the syntax:
transform:scale(1.1,1.2);
transform: matrix(1.1, 0, 0, 1.2, 0, 0);
Let’s take a look at skew again. I translate it as “tilt”. The function of skew is to tilt the component at a certain angle. It can be used to draw parallelograms and resemble the “inertial motion” we have seen before. " is achieved through this. It is more reliable to use a single Skew to demonstrate
transform: skewX(45deg);transform: skewY(45deg);
transform: matrix(1, 0, 1, 1, 0, 0); transform: matrix(1, 1, 0, 1, 0, 0);
At this point, we understand what the six values of the matrix represent:
The first element: X-axis magnification
The second Element: The tan value of the Y-axis tilt angle
The third element: The tan value of the X-axis tilt angle
The fourth element: Remarks for Y-axis amplification
Five elements: the pixel size shifted to the right
The sixth element: the pixel size shifted downward.
It’s not over yet. There is another ratio that has not been explained. Before explaining it, let’s take a look at an illustration:
These two pictures look like Is the effect almost the same? They are indeed almost the same, but the difference is that the above picture is realized through rotate, while the picture below is realized through skew, which is rotated at an angle of 45 degrees. Take a look at the two generated styles respectively:
transform: matrix(0.707106781186548, 0.707106781186548, -0.707106781186548, 0.707106781186548, 0, 0); transform: matrix(1, 0.466307658154999, 0.466307658154999, 1, 0, 0);
Well, it’s no longer simple to say it like this. It’s a bit deviated from my title. Let’s explain it simply and crudely. The above matrix is replaced by: (a,b,c,d,e,f ) six values, then calculate the relative coordinates of each pixel based on the center point, and then calculate the new coordinates. The calculation formula for the new coordinates is:
x' = a * x c * y e; y' = b * x d * y f; When rotating, the values passed in are cosθ, sinθ, sinθ and cosθ respectively, and the values passed in by skew are: cosθ/consθ, sinθ/cosθ, sinθ/cosθ, cosθ/cosθ. So this is why the image is enlarged by a factor of 2 when using skew for rotation.
In fact, under normal circumstances, it is enough to use the matrix formula using the six calculation methods mentioned above. This last part of this article is only written for the completeness of the article, but it has lost the principle of simplicity and crudeness. .

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.
