简体   繁体   English

在设置高度动画时将弹性项目与底部对齐

[英]Align flex items to bottom while animating height

I'm trying to make an equalizer animation and would like these lines to animate from the bottom of the containing DIV as opposed to animating from the top like they are now.我正在尝试制作一个均衡器 animation 并希望这些线条从包含 DIV 的底部进行动画处理,而不是像现在这样从顶部进行动画处理。

 .equalizer { display: flex; flex-direction: row; height: 10px; }.bar { margin-bottom: auto; background-color: #36D475; width: 2px; height: 2px; margin: 1px; animation-name: bar-animation; animation-direction: alternate; animation-iteration-count: infinite; animation-duration: .25s; }.one { animation-delay: .1s; }.two { animation-delay: -.1s; animation-duration: .5s; }.three { animation-delay: -.2s; }.four { animation-delay: -.3s; } @keyframes bar-animation { from { height: 2px;} to { height: 10px;} }
 <div class="equalizer"> <div class="bar one"></div> <div class="bar two"></div> <div class="bar three"></div> <div class="bar four"></div> </div>

I think using transforms might suffice and be lighter than adjusting the height property.我认为使用变换可能就足够了,并且比调整height属性更轻。 The property that will change the orientation is the transform-origin: 0 100% .将改变方向的属性是transform-origin: 0 100% Below the script transforms the bars by scaling from transform: scaleY(1) to transform: scaleY(5) .下面的脚本通过从transform: scaleY(1)缩放到transform: scaleY(5) ) 来转换条形图。

 .equalizer { display: flex; flex-direction: row; height: 10px; align-items: flex-end; }.bar { margin-bottom: auto; background-color: #36D475; width: 2px; height: 2px; margin: 1px; animation-name: bar-animation; animation-direction: alternate; animation-iteration-count: infinite; animation-duration: .25s; transform: scaleY(1); transform-origin: 0 100%; }.one { animation-delay: .1s; }.two { animation-delay: -.1s; animation-duration: .5s; }.three { animation-delay: -.2s; }.four { animation-delay: -.3s; } @keyframes bar-animation { to {transform: scaleY(5);} }
 <div class="equalizer"> <div class="bar one"></div> <div class="bar two"></div> <div class="bar three"></div> <div class="bar four"></div> </div>

Just use align-items: flex-end;只需使用align-items: flex-end; in .equalizer you can also use align-items: center;.equalizer你也可以使用align-items: center; to make them align in center使它们居中对齐

 .equalizer { display: flex; flex-direction: row; height: 10px; align-items: flex-end; }.bar { margin-bottom: auto; background-color: #36D475; width: 2px; height: 2px; margin: 1px; animation-name: bar-animation; animation-direction: alternate; animation-iteration-count: infinite; animation-duration: .25s; }.one { animation-delay: .1s; }.two { animation-delay: -.1s; animation-duration: .5s; }.three { animation-delay: -.2s; }.four { animation-delay: -.3s; } @keyframes bar-animation { from { height: 2px;} to { height: 10px;} }
 <div class="equalizer"> <div class="bar one"></div> <div class="bar two"></div> <div class="bar three"></div> <div class="bar four"></div> </div>

It's quite simple.这很简单。 All you have to do is add align-items: flex-end;您所要做的就是添加align-items: flex-end; to your .equalizer class.到您的.equalizer class。 This will align all the bars to the bottom of the div making it start from the bottom rather than from the top.这会将所有条形对齐到 div 的底部,使其从底部而不是从顶部开始。 The other solution is you can use transform: scaleY(-1);另一个解决方案是您可以使用transform: scaleY(-1); which will flip the whole thing upside down.这会将整个事情颠倒过来。

 .equalizer { display: flex; flex-direction: row; height: 10px; align-items: flex-end; }.bar { margin-bottom: auto; background-color: #36D475; width: 2px; height: 2px; margin: 1px; animation-name: bar-animation; animation-direction: alternate; animation-iteration-count: infinite; animation-duration: .25s; }.one { animation-delay: .1s; }.two { animation-delay: -.1s; animation-duration: .5s; }.three { animation-delay: -.2s; }.four { animation-delay: -.3s; } @keyframes bar-animation { from { height: 2px;} to { height: 10px;} }
 <div class="equalizer"> <div class="bar one"></div> <div class="bar two"></div> <div class="bar three"></div> <div class="bar four"></div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM