自学web的第22天

css3过渡动画——transition属性

  • 语法

transition: transition-proterty transition-duration transition-timing-function transition-delay;
transition: css样式  动画的执行时间  速度类型  动画的延迟时间;
 多个css属性用逗号隔开
 transition: transform 2s, background-color 2s;
​
注意:谁发生了属性的改变 就加在谁身上
  • 属性

    1、transition-proterty

    • css样式:参与过渡的css属性名称|all表示所有属性

    2、transition-duration

    • 动画执行时间:默认0s,s|ms(毫秒) 1s=1000ms

    3、transition-timing-function

    • 速度类型

      1.linear 相同的速度从开始到结束,也就是匀速 2.ease 默认值 慢速度开始--速度变快--慢速度结束 3.ease-in 慢速度开始的过渡效果,也就是以低速度开始 4.ease-out 慢速度结束的过渡效果,也就是以低速结束 5.ease-in-out 以慢速度开始和结束的过渡效果

    4、transition-delay

    • 延迟时间:默认0s,单位s|ms

注意:必须设置transition-duration属性,否则执行时间为0,不会产生过渡效果

<!DOCTYPE html>
<html lang="en">
​
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
​
        .warp {
            width: 400px;
            height: 400px;
            background-color: pink;
        }
​
        .box {
            width: 200px;
            height: 200px;
            background-color: tomato;
            /* 参与过渡的css属性名称 */
            transition-property: width, height, background-color;
            /* 动画执行时间 */
            transition-duration: 2s;
            /* 速度类型 */
            transition-timing-function: linear;
            /* 延迟时间 */
            transition-delay: 2s;
​
            /* 复合写法 */
            transition: width 2s 2s, height 2s 2s, background-color 2s 2s;
​
            /* transition: all 1s linear 2s; */
​
            transition: 2s linear 2s;
​
        }
​
        .warp:hover .box {
            width: 300px;
            height: 300px;
            background-color: blue;
        }
    </style>
</head>
​
<body>
    <div class="warp">
        <div class="box"></div>
    </div>
</body>
​
</html>

css3动画&2D|3D

一、css3的transform属性

1、2D变形:平移、旋转、缩放、倾斜

1) transform: translate()平移

  • transform: translate(x,y) 沿着x轴和y轴移动

  • transform: translateX(x) 沿着x轴移动

  • transform: translateY(y) 沿着y轴移动

取值:

  • px

  • 百分比(强调相对于元素本身计算)

  • 说明:允许负值,正值默认向右向下,负值向左向上

水平向右为正值,垂直方向向下正值

/* 沿着水平方向位移 */
当为一个值的时候,只沿着水平方向位移
transform: translate(50px);

2) transform: rotate(ndeg) 旋转

  • 语法

  • transform:rotate(deg);沿着中心点旋转,默认值

  • transform: rotateX(deg);沿着X轴旋转

  • transform: rotateY(deg);沿着Y轴旋转

单位:deg ​ 当角度值为正数时,元素沿着顺时针方向旋转 ​ 当角度值为负数时,元素沿着逆时针方向旋转

   .box1 {
        background-color: red;
        transform: rotate(45deg);
        }
    .box2 {
        background-color: blue;
        transform: rotate(-45deg);
    }
    .box3:hover {
            transform: rotateX(60deg);
        }
    .box4:hover {
            transform: rotateY(60deg);
        }

3)transform: scale() 缩放

  • transform: scale(x,y) 沿着x轴和y轴缩放

  • transform: scaleX(x) 沿着x轴缩放

  • transform: scaleY(y) 沿着y轴缩放

取值范围0~1之间表示缩小,1表示正常大小,1以上表示放大,默认值为1 取值为负值表示先翻转后缩放

为一个值的时候,沿着水平方向和垂直方向等比例缩放

transform: scale(1.5);/* 沿着水平方向和垂直方向都放大1.5倍,等比例缩放 */
transform: scale(-1.5);/* 先翻转,然后 沿着水平方向和垂直方向都放大1.5倍 */

4)transform: skew() 倾斜

  • transform: skew(x,y) 沿着x轴和y轴倾斜

  • transform: skewX(x) 沿着x轴倾斜

  • transform: skewY(y) 沿着y轴倾斜

单位deg(角度) 正值,向左上角和右下角倾斜;负值,向右上角和左下角倾斜

为一个值的时候,只沿着水平方向倾斜

  /* 为一个值的时候,只沿着水平方向位移 */
        .box1:hover {
            transform: skew(45deg);
        }
 /* skew(30deg,45deg) 围绕 X 轴把元素翻转 30 度,围绕 Y 轴翻转 45 度 */
        .box2:hover {
            background-color: tomato;
            transform: skew(30deg, 45deg);
        }
​
        .box3:hover {
            transform: skewX(-45deg);
        }
​
        .box4:hover {
            transform: skewY(45deg);
​
        }
        .box5:hover {
            transform: skewY(-45deg);
        }

5)transform-origin属性 设置元素的基点位置

  • transform-origin: 水平方向 垂直方向;

  • 设置元素的基点位置,设置围绕哪个点进行变化

  • 取值

百分比

px

关键字

水平:left center right ​ 垂直:top center bottom

  • 说明: 两个空格隔开的值,分别表示x,y轴的原点 一个值时,另一个值默认center

  • 可为负数

必须与transform属性配合使用

<!DOCTYPE html>
<html lang="en">
​
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .wrap {
            width: 300px;
            height: 300px;
            background-color: plum;
            margin: 100px auto;
        }
​
        .wrap .box1 {
            width: 100px;
            height: 100px;
            background-color: blue;
            margin: 0 auto;
            transition: .5s;
            transform-origin: right top;
            transform-origin: bottom;
            transform-origin: 100px 200px;
            transform-origin: 100px;
            transform-origin: 50% 50%;
            transform-origin: -50% -100%;
        }
​
        .wrap:hover .box1 {
            transform: rotate(135deg);
        }
    </style>
</head>
​
<body>
    <div class="wrap">
        <div class="box1">1</div>
    </div>
</body>
​
</html>

5)旋转,位移,缩放,倾斜的复合写法

属性之间用空格隔开,先位移再旋转
​
    .wrap:hover .box1 {
            transform: rotate(135deg);
            transform: translate(50px);
            transform: scale(1.5);
            /* 复合 先位移再旋转*/
            transform: translate(100px) rotate(120deg) scale(1.5);
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值