transform与transition区别与详解

2020-04-27 09:26:49

参考地址 CSS中的transform与transition

transform:转换

对元素进行移动、缩放、转动、拉长或拉伸。

方法:translate():

元素从其当前位置移动,根据给定的 left(x 坐标) 和 top(y 坐标) 位置参数

有两个div,它们的css样式如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.before {
            width70px;
            height70px;
            background-color#8fbc8f;
        }
 
 .after {
            width70px;
            height70px;
            background-color#ffe4c4;
            -webkit-transform: translate(50px30px);
            -moz-transform: translate(50px30px);
            -ms-transform: translate(50px30px);
            -o-transform: translate(50px30px);
            transform: translate(50px30px);
        }

 

结果如下:

rotate()

元素顺时针旋转给定的角度。允许负值,元素将逆时针旋转。

有两个div,它们的css样式如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.before {
            width70px;
            height70px;
            background-color#8fbc8f;
        }
 
.after {
            width70px;
            height70px;
            background-color#ffe4c4;
            -webkit-transform: rotate(20deg);
            -moz-transform: rotate(20deg);
            -ms-transform: rotate(20deg);
            -o-transform: rotate(20deg);
            transform: rotate(20deg);
        }

结果如下:

scale()

元素的尺寸会增加或减少,根据给定的宽度(X 轴)和高度(Y 轴)参数

有两个div,它们的css样式如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.before {
            width70px;
            height70px;
            background-color#8fbc8f;
        }
 
.after {
            width70px;
            height70px;
            background-color#ffe4c4;
            -webkit-transform: scale(1.50.8);/*宽度变为原来的1.5倍,高度变为原来的0.8倍*/
            -moz-transform: scale(1.50.8);
            -ms-transform: scale(1.50.8);
            -o-transform: scale(1.50.8);
            transform: scale(1.50.8);
        }

结果如下:

skew()

元素翻转给定的角度,根据给定的水平线(X 轴)和垂直线(Y 轴)参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
.before {
            width70px;
            height70px;
            background-color#8fbc8f;
        }
 
.after {
            width70px;
            height70px;
            background-color#ffe4c4;
            -webkit-transform: skew(20deg, 20deg);/*围绕 X 轴把元素翻转20度,围绕 Y 轴翻转20度*/
            -moz-transform: skew(20deg, 20deg);
            -ms-transform: skew(20deg, 20deg);
            -o-transform: skew(20deg, 20deg);
            transform: skew(20deg, 20deg);
        }

  

结果如下:

 

 

 

transition:过渡

元素从一种样式逐渐改变为另一种的效果

有一个div,它的css样式如下:

1
2
3
4
5
6
7
8
9
10
11
12
div {
            width:100px;
            height:100px;
            background-color#87cefa;
            -webkit-transition: width 2s;/*时长为2s的宽度变化效果*/
            -moz-transition: width 2s;
            -o-transition: width 2s;
            transition: width 2s;
        }
div:hover{
            width:300px;
        }

 


  • 2019-09-23 16:17:13

    consola 教程

    consola 和 console 只差一个字母,并且它们都是控制器日志输出的好帮手。console 在某些方面,使用有些局限性。consola 是一个功能更丰富,更漂亮的控制台日志输出控件。今天我们一起来学习它的

  • 2019-09-24 22:03:13

    nginx支持socket

    安装nginx,stream模块默认不安装的,需要手动添加参数:–with-stream,根据自己系统版本选择nginx1.9或以上版本。

  • 2019-09-26 13:25:38

    git合并时冲突<<<<<<< HEAD

    head 到 =======里面的lalala是自己的commit的内容 =========到 >>>>>>里面的hehehe是下拉的内容

  • 2019-09-26 18:57:29

    Java中数组怎么深度复制

    有时候循环进行一些操作,放入list,发现,list中的数据都是一个数据,这就尴尬了,我们需要深度复制,才能解决这个问题。或者生成新的,也就是深度复制。

  • 2019-09-26 19:03:33

    spring post jackson的反序列化需要无参构造函数

    JSON parse error: Cannot construct instance of `com.**` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.**` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)  at [Source: (PushbackInputStream); line: 2, column: 2]] ———————————————— 版权声明:本文为CSDN博主「冰夏之夜影」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/u011561335/article/details/91346777