【前端知识点总结】CSS 基础六 - 常见的CSS动画

空间(3d)转换 tramsform: 值 ;

snipaste20220207_084856.png

移动 tramsform:translate3d(x,y,z);

  • 添加位移属性 transform: translate3d(x轴, y轴, z轴);
  • 给盒子父元素添加(perspective视距)视距,实现Z轴转换
  • 视距 perspective:值; 人眼到屏幕的距离,一半约800px-1200px
body {
    /* 视距,是屏幕距眼睛的距离,添加到父元素上, 一般是800px-1200px */
    perspective: 1000px;
}
.box {
    width: 200px;
    height: 200px;
    background-color: #ccc;
    margin: 200px auto;
    transition: all 1s;
}
.box:hover {
    transform: translateX(100px);
    transform: translateY(100px);
    transform: translateZ(200px);
    /* transform: translate3d(x轴, y轴, z轴); */
    transform: translate3d(100px, 100px, 100px);
}

旋转 rotateX() rotateY() rotateZ()

左手法则 : 判断旋转方向: 左手握住旋转轴, 拇指指向正值方向, 手指弯曲方向为旋转正值方向

snipaste20220207_094130.png

  • 旋转属性: transform: rotateX(60deg) rotateY(60deg) rotateZ(60deg);
  • 旋转属性连写: rotate3d(x,y,z,度数) x,y,z取值0-1

立体呈现

给父元素添加 transform-style:preserve-3d; 使子元素处于3d空间

<head>
    <style>
        .box {
            position: relative;
            width: 300px;
            height: 300px;
            margin: 100px auto;
            /* 使子元素处于真正的3d空间,添加到父元素上 */
            transform-style: preserve-3d;
            transition: all 3s;
        }
        .box:hover {
            transform: rotateY(360deg);
        }
        .box div {
            position: absolute;
            width: 100%;
            height: 100%;
        }
        .front {
            background-color: skyblue;
        }
        .back {
            background-color: pink;
            transform: translateZ(-300px);
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="back">后面</div>
        <div class="front">前面</div>
    </div>
</body>

动画 animation 多个状态间的变化过程,动画过程可控

使用动画

  1. 定义动画 @keyframes 动画名称 {}
  2. 调用动画 animation : 值 ;
        .box {
            width: 200px;
            height: 200px;
            background-color: #f00;
            border-radius: 50%;
            /* 2.调用动画 */
            animation: move 1s infinite;
        }
        /* 1.定义动画 */
        @keyframes move {
            /* 可以使用百分比来设置每个时刻的状态
            0% { */
            from {
                transform: translate(0);
            }
            /* 100% { */
            to {
                transform: translate(500px);
            }
        }

动画属性 animation-

  • animation-name: 值 ; 调用动画的名称
  • animation-duration : 值 ; 动画播放的时长
  • animation-delay : 值 ; 延迟 动画等待多久执行
  • animation-fill-mode : 值 ; forwards 停在最后一帧 backwards 默认值 停在第一帧
  • animation-timing-function : 值 ; linear 匀速 速度曲线
  • animation-iteration-count : 值 ; 写数值表示播放次数 infinite 循环播放
  • animation-direction : 值 ; 动画执行方向 alternate 反向播放 逆播
  • animation-play-state : 值 ; 动画暂停 paused 暂停
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

疆子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值