Side note: one reason why I like preprocessors (my go to is Sass) is that necessarily repetitive CSS can be encapsulated in a for loop:
// note: using $factor1 and $factor2 for the multiplication factors to // determine the animation percentages@for$ifrom0through5{@keyframesbar_animate_#{$i}{0%,#{$i*$factor1}%{transform:scaleX(0);transform-origin:left;}#{$i*$factor2}%,100%{transform:scaleX(1);transform-origin:left;}}}
And similarly for the .bar_[i] classes.
One more thing, looks like the CSS in that last block is correct, you set all the animations to bar_animate_5. The Codepen is correct though.
Pretty cool!
There's also
animation-delay
, which is helpful for spacing out the timing of animations: developer.mozilla.org/en-US/docs/W...Side note: one reason why I like preprocessors (my go to is Sass) is that necessarily repetitive CSS can be encapsulated in a
for
loop:And similarly for the
.bar_[i]
classes.One more thing, looks like the CSS in that last block is correct, you set all the animations to
bar_animate_5
. The Codepen is correct though.Thanks for suggesting improvement and pointing out the mistake. I have corrected the mistake now. I will refactor it in the evening.
@Steven, I have refactored the animation to use Sass's for loop and updated the article. Many thanks for suggesting the improvement.