@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函数实现,自定义属性以--符号开头
例子