Để đặt fill-mode cho một animation với CSS, hãy sử dụng thuộc tính animation-fill-mode. Nó có các giá trị forwards, backwards, both cho cả hai hướng, v.v.
Ví dụ
Bạn có thể chạy mã sau để đặt fill-mode cho animation:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 150px;
height: 200px;
position: relative;
background: red;
animation-name: myanim;
animation-duration: 2s;
animation-fill-mode: forwards;
}
@keyframes myanim {
from {left: 0px; background-color: green;}
to {left: 200px; background-color: blue;}
}
</style>
</head>
<body>
<div></div>
</body>
</html>