CSS3 盾牌组合动画

157 阅读1分钟
<!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>
    body {
      background-color: mediumseagreen;
    }
    .box {
      width: 420px;
      height: 491px;
      margin: 100px auto;
      text-align: center;
    }

    /* 通过 transform 打乱图片 */
    img:nth-child(1) {
      transform: translate(-100px, -100px) rotate(123deg);
    }
    img:nth-child(2) {
      transform: translate(-300px, 200px) rotate(23deg);
    }
    img:nth-child(3) {
      transform: translate(300px, -100px) rotate(23deg);
    }
    img:nth-child(4) {
      transform: translate(200px, -200px) rotate(53deg);
    }
    /* 添加动画 */
    img {
      transition: all 1s;
    }
    /* 到.box上则动画恢复原样 */
    .box:hover img {
      /* transform: translate(0px, 0px) rotate(0deg); */
      transform: none;
    }
  </style>
</head>
<body>
  <div class="box">
    <img src="shield_1_01.png" alt="">
    <img src="shield_1_02.png" alt="">
    <img src="shield_1_03.png" alt="">
    <img src="shield_1_04.png" alt="">
    <img src="shield_1_05.png" alt="">
    <img src="shield_1_06.png" alt="">
    <img src="shield_1_07.png" alt="">
    <img src="shield_1_08.png" alt="">
    <img src="shield_1_09.png" alt="">
  </div>
</body>
</html>
  • demo效果