过渡属性篇

transition: width 1s linear 0s;

含义:过渡属性 动画时长 匀速曲线 延迟时长

transform: scale(1.2) rotate(45deg)

含义:放大1.2倍 旋转45度

transition: width 1s cubic-bezier(,,,,) 0s;

网站:https://cubic-bezier.com/

含义:过渡属性 动画时长 贝塞尔曲线 延迟时长

过渡实战1

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>过渡效果1</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            margin: 40px auto;
            width: 1200px;
            overflow: hidden;
            /*background-color: red;*/
        }
        .box ul{
            list-style: none;
        }
        .box ul li{
            float: left;
            width: 380px;
            height: 210px;
            margin-right: 20px;
            position: relative;
        }
        .box ul li img{
            width: 380px;
            height: 210px;
        }
        .box ul li .info{
            position: absolute;
            padding-left: 10px;
            width: 370px;
            height: 30px;
            line-height: 30px;
            bottom: 0;
            color: white;
            background-color: rgba(0,0,0,.5);
            /* 透明度设置为0,不是背景的透明度,而是整体的透明度 */
            opacity: 0;
            /* 过渡 */
            transition: opacity 1s ease 0s;
        }
        /* 当li被触碰的时候,内部的info盒子就要把透明度变为1 */
        .box ul li:hover .info {
            opacity: 1;
        }
    </style>
</head>
<body>
<div class="box">
    <ul>
        <li>
            <img src="images/0.jpg" alt="">
            <div class="info">北京的故宫</div>
        </li>
        <li>
            <img src="images/0.jpg" alt="">
            <div class="info">鸟巢体育场</div>
        </li>
        <li>
            <img src="images/0.jpg" alt="">
            <div class="info">十七孔桥</div>
        </li>
    </ul>
</div>
</body>
</html>

过渡实战2 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>过渡效果2</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .box{
            width: 508px;
            height: 107px;
            /*background-color: red;*/
            margin: 40px auto;
        }
        .box ul{
            list-style: none;
        }
        .box ul li{
            float: left;
            width: 107px;
            height: 107px;
            margin-right: 20px;
            position: relative;
        }
        .box ul li::before{
            content: '';
            display: block;
            width: 107px;
            height: 107px;
            transform: rotate(0);
            transition: transform 1s ease 0s;
        }
        .box ul li:nth-child(1)::before{
            background-image: url("images/a_1.png");
        }
        .box ul li:nth-child(2)::before{
            background-image: url("images/a_2.png");
        }
        .box ul li:nth-child(3)::before{
            background-image: url("images/a_3.png");
        }
        .box ul li:nth-child(4)::before{
            background-image: url("images/a_4.png");
        }
        .box ul li img{
            position: absolute;
            width: 60px;
            height: 60px;
            top: 50%;
            left: 50%;
            margin-left: -30px;
            margin-top: -30px;
            transition: transform .5s ease 0s;
        }
        /* 背景圆环旋转一周 */
        .box ul li:hover::before{
            transform: rotate(360deg);
        }
        /* 中心图标放大1.2倍 */
        .box ul li:hover img{
            transform: scale(1.2);
        }
    </style>
</head>
<body>
<div class="box">
    <ul>
        <li><img src="images/icon1.svg"></li>
        <li><img src="images/icon2.svg"></li>
        <li><img src="images/icon3.svg"></li>
        <li><img src="images/icon4.svg"></li>
    </ul>
</div>

</body>
</html>

过渡效果3 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>过渡效果3</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        .box {
            width: 200px;
            height: 200px;
            /*border: 1px solid #000;*/
            margin: 40px auto;
            /*有2D和3D,需要加perspective属性*/
            perspective: 500px;
            position: relative;
        }
        .box img{
            width: 200px;
            height: 200px;
            border-radius: 50%;
            /*后面才加上边框的*/
            border: 1px solid #000;
        }
        .box img.dog{
            position: absolute;
            top: 0;
            left: 0;
            /*水平垂直轴 从左边开*/
            transform-origin: 0 0;
            transition: transform 1s ease 0s;
        }
        .box:hover img.dog{
            transform: rotateY(-180deg);
        }
        .no2 img.dog{
            /*水平垂直轴 从右边开*/
            transform-origin: 100% 100%;
            transition: transform 1s ease 0s;
        }
        .no2:hover img.dog{
            transform: rotateY(180deg);
        }
        .no3 img.dog{
            /*水平垂直轴 从上边开*/
            transform-origin: 0 0;
            transition: transform 1s ease 0s;
        }
        .no3:hover img.dog{
            transform: rotateX(180deg);
        }
    </style>
</head>
<body>
<div class="box">
    <img class="cat" src="images/cat.jpg" alt="">
    <img class="dog" src="images/dog.jpg" alt="">
</div>
<div class="box no2">
    <img class="cat" src="images/cat.jpg" alt="">
    <img class="dog" src="images/dog.jpg" alt="">
</div>
<div class="box no3">
    <img class="cat" src="images/cat.jpg" alt="">
    <img class="dog" src="images/dog.jpg" alt="">
</div>
</body>
</html>

过渡效果4 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>正方体</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        section{
            width: 200px;
            height: 200px;
            margin: 100px auto;
            /*透视效果设置大点,不然会发生扭曲,看起来不像正方体*/
            perspective: 10000px;
        }
        .box {
            width: 200px;
            height: 200px;
            perspective: 10000px;
            position: relative;
            /*设置变形类型,保留它内部的3D效果*/
            /*这个盒子又是舞台,又是演员,这个box整体带着里面的p旋转*/
            transform-style: preserve-3d;
            transition: all 10s ease 0s;
        }
        section:hover .box{
            transform: rotateX(360deg) rotateY(360deg);
        }
        .box p{
            position: absolute;
            top: 0;
            left: 0;
            width: 200px;
            height: 200px;
        }
        .box p:nth-child(1){
            background-color: rgba(219,56,211,0.486);
            /*前面*/
            transform: translateZ(100px);
        }
        .box p:nth-child(2){
            background-color: rgba(42,128,199,0.486);
            /*顶面 后仰*/
            transform: rotateX(90deg) translateZ(100px);
        }
        .box p:nth-child(3){
            background-color: rgba(56,219,83,0.486);
            /*背面 后仰*/
            transform: rotateX(180deg) translateZ(100px);
        }
        .box p:nth-child(4){
            background-color: rgba(213,216,32,0.486);
            /*底面 前倾*/
            transform: rotateX(-90deg) translateZ(100px);
        }
        .box p:nth-child(5){
            background-color: rgba(236,82,102,0.486);
            /*侧面*/
            transform: rotateY(90deg) translateZ(100px);
        }
        .box p:nth-child(6){
            background-color: rgba(119,17,236,0.486);
            /*侧面*/
            transform: rotateY(-90deg) translateZ(100px);
        }
    </style>
</head>
<body>
<!--div对于p来说是舞台,对于section来说是演员-->
<section>
    <div class="box">
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
        <p></p>
    </div>
</section>
</body>
</html>

动画定义

动画名字 动画时间 速度曲线 延迟时间 次数 


<!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>
        .box1 {
            width: 200px;
            height: 200px;
            background-color: orange;
            animation: r 1s linear 0s infinite 3;
        }

        @keyframes r {
            from {
                transform: rotate(0);
            }

            to {
                transform: rotate(360deg);
            }
        }

        .box2 {
            width: 200px;
            height: 200px;
            background-color: blue;
            animation: movelr 2s linear 0s infinite alternate;
        }

        @keyframes movelr {
            from {
                transform: translateX(0);
            }
            to {
                transform: translateX(1000px);
            }
        }

        .box3 {
            width: 200px;
            height: 200px;
            background-color: green;
            animation: changeToCircle 1s linear 0s forwards;
        }

        @keyframes changeToCircle {
            from {
                border-radius: 0;
            }
            to {
                border-radius: 50%;
            }
        }

        .box4 {
            width: 200px;
            height: 200px;
            background-color: red;
            animation: changeColor 3s linear 0s alternate infinite;
        }

        @keyframes changeColor {
            0% {
                background-color: red;
            }
            20% {
                background-color: yellow;
            }
            40% {
                background-color: blue;
            }
            60% {
                background-color: green;
            }
            80% {
                background-color: purple;
            }
            100% {
                background-color: orange;
            }
        }
    </style>
</head>

<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
    <div class="box4"></div>
</body>

</html>

动画实战2 


<!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;
        }
        .dengpao {
            position: absolute;
            top: 300px;
            left: 300px;
        }
        .guang {
            position: absolute;
            top: 235px;
            left: 222px;
            animation: ss 1s ease 0s infinite alternate;
        }

        @keyframes ss {
            from {
                opacity: 1;
            }
            to {
                opacity: 0;
            }
        }

        .huojian {
            position: absolute;
            top: 300px;
            left: 800px;
            animation: zd .4s linear 0s infinite alternate;
        }

        @keyframes zd {
            from {
                transform: translateX(-20px) translateY(-20px);
            }
            to {
                transform: translateX(20px) translateY(20px);
            }
        }

        .line1 {
            width: 2px;
            height: 166px;
            background-color: blue;
            position: absolute;
            top: 300px;
            left: 800px;
            transform: rotate(45deg);
            animation: yd 1s linear 0s infinite;
            opacity: 0;
        }
        .line2 {
            width: 2px;
            height: 266px;
            background-color: blue;
            position: absolute;
            top: 340px;
            left: 850px;
            transform: rotate(45deg);
            animation: yd 1s linear .4s infinite;
            opacity: 0;
        }
        .line3 {
            width: 2px;
            height: 266px;
            background-color: blue;
            position: absolute;
            top: 390px;
            left: 890px;
            transform: rotate(45deg);
            animation: yd 1s linear .68s infinite;
            opacity: 0;
        }
        .line4 {
            width: 2px;
            height: 266px;
            background-color: blue;
            position: absolute;
            top: 390px;
            left: 920px;
            transform: rotate(45deg);
            animation: yd 1s linear .2s infinite;
            opacity: 0;
        }
        @keyframes yd {
            0% {
                transform: rotate(45deg) translateY(-300px);
                opacity: 0;
            }
            50% {
                opacity: 1;
            }
            100% {
                transform: rotate(45deg) translateY(300px);
                opacity: 0;
            }
        }
    </style>
</head>
<body>
    <img class="dengpao" src="images/dengpao.png" alt="">
    <img class="guang" src="images/guang.png" alt="">

    <img class="huojian" src="images/huojian.png" alt="">
    <div class="line1"></div>
    <div class="line2"></div>
    <div class="line3"></div>
    <div class="line4"></div>
</body>
</html>

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值