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

Đặt animation chạy xuôi hay ngược với CSS

Sử dụng thuộc tính animation-direction để đặt xem một animation nên được phát xuôi, ngược hay theo chu kỳ luân phiên:

Ví dụ

<!DOCTYPE html>
<html>
  <head>
    <style>
      div {
        width: 150px;
        height: 200px;
        background-color: yellow;
        animation-name: myanim;
        animation-duration: 2s;
        animation-direction: reverse;
      }
      @keyframes myanim {
        from {
          background-color: green;
        }
        to {
          background-color: blue;
        }
      }
    </style>
  </head>
  <body>
    <div></div>
  </body>
</html>