@keyframes around { from { margin-left: 100%; } to { margin-left: -5em; } }
那個-5em應該是參數傳進去的?可以解決嗎?
光阴似箭催人老,日月如移越少年。
設定自訂CSS屬性結合var函數實現,自訂屬性以--符號開頭範例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> @keyframes around { from { margin-left: 100%; } to { margin-left: var(--margin-left); } } .main{ position: absolute; left:0p; top:0px; width: 200px; height: 200px; background-color: #7C2845; color:#ffffff; --margin-left:-5em; } .main.active{ animation-name: around; animation-duration: 1s; animation-direction: alternate; animation-iteration-count: infinite; } </style> </head> <body> <p class="main active"> TEST </p> </body> </html>
設定自訂CSS屬性結合var函數實現,自訂屬性以--符號開頭
範例