CSS3 transition 背景图片 - 过渡动画

121 阅读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>
    .box {
      width: 300px;
      height: 150px;
      margin: 100px auto;
      border-radius: 10px;

      background: url(paopao.png) no-repeat left top, url(paopao.png) no-repeat right bottom;
      /* background-color 放在 background 之前会被覆盖掉不生效,所以需要放在它后面 */
      background-color: orange;

      /* 过渡动画 */
      transition: all 1s;
    }
    .box:hover {
      background-position: left bottom, right top;
    }
  </style>
</head>
<body>
  <div class="box"></div>
</body>
</html>
  • demo 效果

  • 泡泡素材

paopao.png