css - Kann @keyframes Parameter akzeptieren?
大家讲道理
大家讲道理 2017-06-16 09:19:25
0
1
988
@keyframes around {
    from {
      margin-left: 100%;
    }
    to {
      margin-left: -5em;
    }
  }

Dass -5em als Parameter übergeben werden soll? Kann es gelöst werden?

大家讲道理
大家讲道理

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

Antworte allen(1)
Peter_Zhu

设置自定义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>
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!