(13)前端-初识HTML与CSS-过渡、动画与2D转换案例

(13)前端-初识HTML与CSS-过渡、动画与2D转换案例

1、过渡

手风琴效果
<!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>
    * {
      margin: 0;
      padding: 0;
      list-style: none;
    }
    ul {
      width: 960px;
      height: 300px;
      margin: 50px auto;
      overflow: hidden;
      border: 5px solid pink;
    }
    ul li {
      width: 160px;
      height: 300px;
      float: left;
      transition: width 0.5s;
    }
    ul:hover li {
      width: 100px;
    }
    ul li:hover {
      width: 400px;
    }
  </style>
</head>

<body>
  <ul>
    <!-- 图片路径自行改变 -->
    <li><img src="./images/ad7.jpeg" alt=""></li>
    <li><img src="./images/ad8.jpg" alt=""></li>
    <li><img src="./images/ad9.jpeg" alt=""></li>
    <li><img src="./images/ad10.jpg" alt=""></li>
    <li><img src="./images/ad11.jpg" alt=""></li>
    <li><img src="./images/ad12.jpg" alt=""></li>
  </ul>
</body>
</html>
文字过渡效果
<!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>
    * {
      margin: 0;
      padding: 0;
    }
    div {
      height: 200px;
      background-color: aqua;
      text-align: center;
      margin: 100px auto;
    }
    div span {
      line-height: 200px;
      transition: font-size 1s linear, margin-left 1s linear,color 1s linear;
    }
    div:hover span {
      font-size: 70px;
      margin-left: 20px;
      color: white;
    }
  </style>
</head>
<body>
  <div>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
  </div>
</body>
</html>

2、动画

简单轮播图
<!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>
    * {
      margin: 0;
      padding: 0;
      list-style: none;
    }
    div {
      width: 800px;
      height: 300px;
      overflow: hidden;
      margin: 50px auto;
      border: 5px solid pink;
    }
    div ul {
      width: 3000px;
      height: 300px;
      animation: swipe 8s linear infinite;
    }
    div ul li {
      width: 400px;
      height: 300px;
      float: left;
    }
    ul:hover li {
      opacity: 0.3;
    }
    ul li:hover {
      opacity: 1;
    }
    div ul li img {
      width: 400px;
      height: 300px;
    }
    @keyframes swipe {
      from {
        margin-left: 0;
      }
      to {
        margin-left: -1600px;
      }
    }
  </style>
</head>
<body>
  <div>
    <ul>
      <!-- 图片路径自行改变 -->
      <li><img src="./images/ad7.jpeg" alt=""></li>
      <li><img src="./images/ad8.jpg" alt=""></li>
      <li><img src="./images/ad9.jpeg" alt=""></li>
      <li><img src="./images/ad10.jpg" alt=""></li>
      <li><img src="./images/ad11.jpg" alt=""></li>
      <li><img src="./images/ad12.jpg" alt=""></li>
    </ul>
  </div>
</body>
</html>
呼吸灯
<!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>
    * {
      margin: 0;
      padding: 0;
    }
    /* 设置背景样式 */
    .bg {
      width: 500px;
      height: 500px;
      background-color: gray;
      margin: 50px auto;
      position: relative;
      box-sizing: border-box;
    }
    .smallCircle {
      width: 300px;
      height: 300px;
      border: 20px solid white;
      position: absolute;
      /* 使用绝对定位实现水平垂直居中 */
      left: 50%;
      top: 50%;
      margin-left: -150px;
      margin-top: -150px;
      /* 切换盒模型 */
      box-sizing: border-box;
      border-radius: 50%;
      /* 设置动画 */
      animation: circle 5s ease infinite alternate-reverse;
    }
    .bigCircle {
      width: 400px;
      height: 400px;
      border: 5px solid white;
      position: absolute;
      /* 使用绝对定位实现水平垂直居中 */
      /* 切换盒模型 */
      left: 50%;
      top: 50%;
      margin-top: -200px;
      margin-left: -200px;
      box-sizing: border-box;
      border-radius: 50%;
      /* 设置动画 */
      animation: circle 5s ease infinite alternate;
    }

    /* 定义动画 */
    @keyframes circle {
      0% {
        border-color: white;
        /* 改变形状的大小 transform */
        transform: scale(0.6);
      }
      25% {
        border-color: antiquewhite;
        transform: scale(0.7);
      }
      50% {
        border-color: yellow;
        transform: scale(0.8);
      }
      75% {
        border-color: orange;
        transform: scale(0.9);
      }
      100% {
        border-color: red;
        transform: scale(1);
      }
    }
  </style>
</head>
<body>
  <div class="bg">
    <div class="bigCircle">
      <div class="smallCircle"></div>
    </div>
  </div>
</body>
</html>
太极图
<!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>
    * {
      margin: 0;
      padding: 0;
    }
    .father {
      margin: 50px auto;
      height: 200px;
      width: 200px;
      display: flex;
      border-radius: 50%;
      animation: circle-animation 10s linear infinite;
    }
    /* 定义动画 */
    @keyframes circle-animation {
      from {
        transform: rotate(0deg);
      }

      to {
        transform: rotate(360deg);

      }
    }
    .father>div {
      width: 100px;
      height: 200px;
      border: 1px solid black;
    }
    .black {
      border-radius: 100px 0 0 100px;
      display: flex;
      background-color: black;
    }
    .white {
      border-radius: 0 100px 100px 0;
      display: flex;
      background-color: white;
    }
    .smallBlack,
    .smallWhite {
      width: 100px;
      height: 101px;
      border-radius: 50%;
      position: relative;
    }
    .smallBlack {
      background-color: black;
      left: 50px;
      top: -1px;
    }
    .smallWhite {
      background-color: white;
      right: 50px;
      top: 99.5px;
    }
    .smallerWhite,
    .smallerBlack {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      position: relative;
      left: 35px;
      top: 35px;
    }
    .smallerWhite {
      background-color: white;

    }
    .smallerBlack {
      background-color: black;
    }
    .description {
      margin: 0 auto;
      text-align: center;
      font-size: x-large;
      font-weight: bold;
    }
  </style>
</head>
<body>
  <div class="father">
    <div class="black">
      <div class="smallBlack">
        <div class="smallerWhite"></div>
      </div>
    </div>
    <div class="white">
      <div class="smallWhite">
        <div class="smallerBlack"></div>
      </div>
    </div>
  </div>
  <div class="description">
    道可道,非常道
  </div>
</body>
</html>

3、2D转换

旋转 变形 动画
<!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>方到圆</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .square {
      width: 300px;
      height: 300px;
      background-color: pink;
      margin: 80px auto;
      animation: square-to-circle 5s infinite alternate;
    }
    /* 定义动画 */
    @keyframes square-to-circle {
      0% {
        background-color: pink;
        border-radius: 0%;
        transform: rotate(0deg);
      }
      25% {
        background-color: aqua;
        border-radius: 50% 0 0 0;
        transform: rotate(45deg);
      }
      50% {
        background-color: royalblue;
        border-radius: 50% 50% 0 0;
        transform: rotate(90deg);
      }
      75% {
        background-color: blueviolet;
        border-radius: 50% 50% 50% 0;
        transform: rotate(135deg);
      }
      100% {
        background-color: crimson;
        border-radius: 50% 50% 50% 50%;
        transform: rotate(180deg);
      }
    }
  </style>
</head>
<body>
  <!-- 方形 -->
  <div class="square"></div>
</body>
</html>

image-20210916152135272

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值