Transform performs 2d and 3d deformation (css Animation 1), transformcss

Source: Internet
Author: User

Transform performs 2d and 3d deformation (css Animation 1), transformcss
This is my understanding and arrangement after learning. If you have any errors or questions, please correct them and I will keep updating them!

 

For some time, I did not clarify the relationships between transform, translate, transition, and animation. Now I want to sort it out:

  • Translate: translation. It is an attribute of transform;
  • Transform: deformation. It is a static attribute that can change the shape or position of an element to make 2d or 3d effects;
  • Transition: transition and transformation. It is a simplified version of animation to make the css attribute values change smoothly within a period of time and requires a trigger condition (such as hover;
  • Animation: animation; you can set multiple frames, and then combine and transform them to display them according to the animation effect;


  • Transform, which can be set to translate (displacement) rotate (rotation) scale (scaling) skew (skew );Multiple values are accepted, separated by spaces, and executed in the previous and subsequent order.;
  • Transform-origin, which can be used to change the benchmark of the conversion element (default value, element center, 50% 50% 0 );
  • Transform-style, which can be set to flat (default value, 2d display) or preserve-3d (3d display); this property must be used after transform;
  • Perspective: Set the element distance from the view. The default value is 0;
  • Perspective-origin, set the viewpoint (default value, element center, 50% 50%), must be used with perspective;
  • Backface-visibility: Specifies whether the elements are visible when they are not facing the screen;
1. translate

Translate)

  • It can be a negative value. It is a positive value to the right and a negative value to the left;
  • Can be a percentage,The percentage is based on the width of the element.(We can use this to realize vertical center of elements with unknown width height );
  • 2d effects can be split into translateX (x), translateY (y), or directly translated into translate (x, y). If only one value is written in the abbreviation, the default value is x;
  • 3d effects include translateZ (z), which is short for translate3d (x, y, z). If it is short for 3d effects, three values must be written, but none can be written, no value can be set to 0;
2. rotate

Rotate)

  • A negative value can be set; a positive value is clockwise and a negative value is clockwise;
  • Can be written as rotateX (deg), rotateY (deg), rotateZ (deg); (angle unit, negative 30 degrees is-30deg)
3. scale

Scale)

  • It can be an integer, a decimal number, or a negative value;
  • It can be written as scaleX (x), scaleY (y), scaleZ (z), or scale (x, y) or scale3d (x, y, z );
  • When a value is set to 0The element is invisible, but the space is still, The same effect as visibility: hidden;
  • When a negative value is setFlip Effect;
  • The scaling seems to have changed the size, but the occupied space remains unchanged without affecting the layout;

The Code is as follows:


<! DOCTYPE html>
<html>
     <head>
         <meta charset = "UTF-8">
         <title> </ title>
         <style type = "text / css">
             * {
                 padding: 0;
                 margin: 0;
             }
             .wrapper {
                 width: 300px;
                 margin: 100px 0 0 100px;
                 border: 10px solid red;
             }
             .test {
                 width: 200px;
                 height: 200px;
                 display: inline-block;
                 background: # 0ff;
                 transform: scale (.5, -1);
                 border: 1px solid # f60;
             }
              .test img {
                 max-width: 100%;
             }
         </ style>
     </ head>
     <body>
         <div class = "wrapper">
             <span class = "test"> <img src = "images / 1.jpg" /> </ span>
             <span> scale can be set to a decimal or negative value; although the size seems to change, the occupied space does not change and it will not affect the layout
         </ div>
     </ body>
</ html>


4. skew
Skew (inclined)

It can be written as skewX (deg), skewY (deg), or abbreviated as skew (x, y). If only one value is written, the default is only the x axis
There is currently no tilt of the Z axis;
Inclining around the X axis will keep the height unchanged, stretching the element, causing deformation; Inclining around the Y axis, will keep the width unchanged;
Can write negative values (for the positive and negative values of the X axis);
  code show as below:


<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            *{
                padding: 0;
                margin: 0;
            }
            .wrapper{
                width: 300px;
                height: 300px;
                position: relative;
                margin: 100px 0 0 100px;
                border: 1px solid red;
                background: #0ff;
            }
            .test{
                width: 150px;
                height: 60px;
                position: absolute;
                left: 30%;
                top: 30%;
                background: #f60;
                transform: skewX(-45deg);
            }
        </style>
    </head>
    <body>
        <div class="wrapper">
            <div class="test"></div>
        </div>
    </body>
</html>



View Code 5. transform-origin
Set the reference point of the transformation element, and then the deformation of the element expands around this point;

The default value is the element center (50% 50% 0);
X and Y axis can set unit value, percentage, left | center | right | top | bottom; Z axis can only set specific unit value;
You can set 1-3 values, separated by spaces. If only one is written, then it is only the X axis; if two, it is the X and Y axes;
 6. transform-style
Set how elements and their children are displayed in three-dimensional space;

The default value is flat, 2d plane; set to preserve-3d, which is 3d space;
When overflow: hidden is set on an element, preserve-ed fails;
Generally we use it on the element's parent element, because this attribute can be inherited;
7. prespective
Set the distance of the element from the view

 

The default is none (0); specific values can be set in pixels, not negative values;
When we look at distant objects, we can see that it is not clear. When we get closer, we can see it clear. This attribute can be understood as the distance between our position and the object;
We generally use it on the parent element of the deformed element, because the browser will produce a perspective effect for its child elements, and will not produce a perspective effect for itself; the element that sets this property is also called a perspective element;
8. prespective-origin
Set the viewpoint;

The default value (50% 50%), you can set the unit value, percentage, left | center | right | top | center | bottom;
You can set 1-2 values. When setting one value, the other defaults to center;
Can be understood as the position, face when we look at the girl? leg? chest?
This attribute must be defined on the element where the prospective attribute is set;
9. backface-visibility
Set whether the element is visible when the element is not facing the screen; this property is useful if you do not want to see the back of the rotated element;

Visible by default, hidden can be set;
  code show as below:

The cube needs to be rotated 180 degrees around the Y axis.


<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="css/base.css"/>    
    </head>
    <body>
        <style type="text/css">
            *{padding: 0;margin: 0;}
            li{list-style: none;}
            /*定义舞台容器*/
            .panel{
                width: 800px;
                margin: 100px auto;
                perspective: 1300px;/*定义视距*/

            }
            .panel:hover ul{
                transform: rotateY(60deg)rotateZ(45deg);
            }
            /*立方体*/
            ul{
                width: 100px;
                height: 100px;
                margin: auto;
                position: relative;
                transform-style:preserve-3d;/*定义该立方体是个3D元素*/
                transform: rotateX(-30deg) rotateY(20deg);
                transition: all 2s;
                cursor: pointer;
            }
            /*立方体六个面*/
            li{
                width: 100px;
                height: 100px;
                position: absolute;
                top: 0;
                left: 0;

                font: 30px/100px "微软雅黑";
                text-align: center;
                color: #fff;
                backface-visibility: hidden;
            }
            .front{
                transform: translateZ(50px) ;
                background: rgba(0,255,0,.6);
            }
            .back{
                transform: translateZ(-50px) rotateY(180deg) ;
                /*后面要旋转绕Y轴180度,我一开始没想起来,调了很久*/
                background: rgba(255,0,255,.6);
            }
            .left{
                transform: translateX(-50px) rotateY(-90deg);
                background: rgba(0,0,255,.6);
            }
            .right{
                transform: translateX(50px) rotateY(90deg);
                background: rgba(255,255,0,.6);
            }
            .top{
                transform: translateY(-50px) rotateX(90deg);
                background: rgba(255,0,0,.6);
            }
            .bottom{
                transform: translateY(50px) rotateX(-90deg);
                background: rgba(0,255,255,.6);
            }
        </style>
        <div class="panel">
            <ul>
                <li class="top">上</li>
                <li class="bottom">下</li>
                <li class="left">左</li>
                <li class="right">右</li>
                <li class="front">前</li>
                <li class="back">后</li>
            </ul>
        </div>
    </body>
</html>





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.