I am currently working on a bar chart that features gradient backgrounds on the bars. The height of the gradient remains constant, and I have implemented clip path to display only a portion of each bar. This ensures that the darkest part of the gradient is always at 100% height.
However, I have encountered an issue when trying to animate each bar from a height of 0px to its designated height. Initially, I attempted to animate the clip-path using various methods such as animation, transition, and transform but was unsuccessful. Subsequently, I tried animating the bars themselves using CSS animations - which partially worked. Unfortunately, the bars expanded from the top down instead of the desired bottom-up effect. You can view my implementation in this JSFiddle.
My question is: How can I achieve the desired effect of making the bars expand from the bottom up?
.barChart { clear: both; height: 70px; width: 170px; border-bottom: solid 2px #eee; }
.bar {
float: left;
margin: 4px;
width: 6px;
background: linear-gradient(to top, #8BC2CA 0%, #2E92A0 100%);
animation: expandBar 2s ease;
animation-fill-mode: forwards;
}
.bar1 { clip-path: inset(80% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar2 { clip-path: inset(20% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar3 { clip-path: inset(60% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar4 { clip-path: inset(80% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar5 { clip-path: inset(20% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar6 { clip-path: inset(60% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar7 { clip-path: inset(80% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar8 { clip-path: inset(20% 0 0 0 round 1.5px 1.5px 0px 0px); }
.bar9 { clip-path: inset(60% 0 0 0 round 1.5px 1.5px 0px 0px); }
@keyframes expandBar{
0% {
height: 0;
}
100%{
height: 60px;
}
}
<div class="barChart">
<div class="bar bar1"></div>
<div class="bar bar2"></div>
<div class="bar bar3"></div>
<div class="bar bar4"></div>
<div class="bar bar5"></div>
<div class="bar bar6"></div>
<div class="bar bar7"></div>
<div class="bar bar8"></div>
<div class="bar bar9"></div>
</div>