CSS 動畫播放結束後,元素預設可能會回到動畫開始前的狀態。若希望動畫停在最後一幀,可以使用 animation-fill-mode: forwards;。
例如:
animation: arrowsfirst 1s;
animation-timing-function: linear;
animation-fill-mode: forwards;
若需要兼容部分舊版 WebKit 瀏覽器,也可以加上前綴:
-webkit-animation: arrowsfirst 1s;
-webkit-animation-timing-function: linear;
-webkit-animation-fill-mode: forwards;
forwards 會讓元素在動畫結束後,保留最後一個關鍵影格所設定的樣式。這很適合用於進場動畫、箭頭位移、淡入後保持顯示等情境。
如果不希望動畫結束後恢復原樣,只要加上 animation-fill-mode: forwards;,就能讓最後狀態持續保留。