Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> CSS

Đặt animation chạy hay tạm dừng với CSS

Sử dụng thuộc tính animation-play-state để đặt xem animation đang chạy hay tạm dừng với CSS.

Ví dụ

Bạn có thể chạy mã sau để đặt animation ở trạng thái tạm dừng:

<!DOCTYPE html>
<html>
  <head>
    <style>
      div {
        width: 150px;
        height: 200px;
        position: relative;
        background: red;
        animation-name: myanim;
        animation-duration: 2s;
        animation-play-state: paused;
      }
      @keyframes myanim {
        from {left: 0px; background-color: green;}
        to {left: 100px; background-color: blue;}
      }
    </style>
  </head>
  <body>
    <div></div>
  </body>
</html>