将CSS动画迁移至Flutter项目的更优方案探讨
将CSS动画迁移到Flutter的更优方案探讨
近期和其他设计师协作,他们提供了一批来自Codepen的CSS动画示例(复杂度不一),需要应用到当前的Flutter项目中。以下是其中一个音乐均衡器风格的动画代码:
CSS代码
* { margin: 0; padding: 0; box-sizing: border-box; } body { display: flex; align-items: center; justify-content: center; height: 100vh; background-color: black; } .music { display: inline-flex; align-items: center; justify-content: space-between; position: relative; width: 300px; height: 200px; } .music .bar { width: 12px; height: 2px; border-radius: 10px; background-color: white; animation: up_down 1.5s ease-in-out infinite; } @keyframes up_down { 0%, 100% { height: 2px; } 50% { height: 80px; } } .music .bar:nth-child(1) { background-color: purple; animation-delay: 1s; } .music .bar:nth-child(2) { background-color: crimson; animation-delay: 0.8s; } .music .bar:nth-child(3) { background-color: deeppink; animation-delay: 0.6s; } .music .bar:nth-child(4) { background-color: orange; animation-delay: 0.4s; } .music .bar:nth-child(5) { background-color: gold; animation-delay: 0.2s; } .music .bar:nth-child(6) { background-color: gold; animation-delay: 0.2s; } .music .bar:nth-child(7) { background-color: orange; animation-delay: 0.4s; } .music .bar:nth-child(8) { background-color: deeppink; animation-delay: 0.6s; } .music .bar:nth-child(9) { background-color: crimson; animation-delay: 0.8s; } .music .bar:nth-child(10) { background-color: purple; animation-delay: 1s; }
HTML代码
<div class='music'> <div class='bar'></div> <div class='bar'></div> <div class='bar'></div> <div class='bar'></div> <div class='bar'></div> <div class='bar'></div> <div class='bar'></div> <div class='bar'></div> <div class='bar'></div> <div class='bar'></div> </div>
我已经用Flutter Canvas实现了这个动画,但想了解是否存在更简便的方法将这类CSS动画迁移到Flutter项目中——毕竟在网页中应用这类动画原本十分轻松。
内容的提问来源于stack exchange,提问作者yellowgray
相关产品推荐
相关产品推荐

