css - Can @keyframes accept parameters?
大家讲道理
大家讲道理 2017-06-16 09:19:25
0
1
1034
@keyframes around {
    from {
      margin-left: 100%;
    }
    to {
      margin-left: -5em;
    }
  }

The -5em should be passed in as a parameter? Can it be solved?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
Peter_Zhu

Set custom CSS properties combined with the var function. The custom properties start with the -- symbol
Example

<!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>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template