CSS特效(14)——纯 CSS 方式实现 CSS 动画的暂停与播放

纯 CSS 方式实现 CSS 动画的暂停与播放

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .animation {
      width: 100px;
      height: 100px;
      margin: 50px auto;
      background: deeppink;
      animation: move 2s linear infinite alternate;
    }


    @keyframes move {
      0% {
        transform: translate(-100px, 0);
      }
      100% {
        transform: translate(100px, 0);
      }
    }

    .btn {
      width: 50px;
      margin: 10px auto;
      text-align: center;
      border: 1px solid #ddd;
      padding: 10px;
      border-radius: 5px;
      cursor: pointer;
    }
    .btn:hover {
        background: #ddd;
        color: #333;
      }

      .btn:active {
        background: #aaa;
      }
    .stop:hover~.animation {
      animation-play-state: paused;
    }
  </style>
</head>

<body>
  <div class="btn stop">stop</div>

  <div class="animation"></div>
</body>

</html>
posted @ 2018-09-07 15:35  Janas  阅读(197)  评论(0编辑  收藏  举报