css - @keyframes 能接受參數嗎?
問題描述
@keyframes around { from { margin-left: 100%; } to { margin-left: -5em; } }
那個-5em應該是參數傳進去的?可以解決嗎?
問題解答
回答1:設置自定義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>
相關文章:
1. 淺談vue生命周期共有幾個階段?分別是什么?2. index.php錯誤,求指點3. angular.js - angularjs ng-class指令改變ng-click點擊的class屬性失效4. android - recyclerview顯示錯亂5. javascript - js中關于閉包的問題,昨晚糾結到了現在,已經快死了6. macos - mac下docker如何設置代理7. 為何java不易熱部署8. jquery插件開發中css應該放在哪?9. 微信公眾號在線生成二維碼帶參數怎么搞?10. 微信開放平臺 - android 微信支付后點完成按鈕,后回調打開第三方頁面,屏幕閃動,求解決方法
