I have created an SVG of the letter "Z" and I am attempting to use it as a loader on my website. I want to animate the three lines of the "Z" to appear sequentially - first the top line, then the middle line, and finally the bottom line. I have tried to create the animation, but when set to infinite, it doesn't work properly. I also experimented with using the animation-delay
property, but it did not give me the desired result.
Here is the code I am currently using:
/* Styling */
*{box-sizing: border-box}html { box-sizing: border-box; font-size: 16px; } *, *:before, *:after { box-sizing: inherit; } body, h1, h2, h3, h4, h5, h6, p, ol, ul { margin: 0; padding: 0; font-weight: normal; } ol, ul { list-style: none; } img { max-width: 100%; height: auto; }body{height: 100vh; display: flex; align-items: center}
/* Animation */
.ZLogo{
margin: 0 auto;
width: 80px;
height: 80px;
padding: 12px 18px;
}
.topBar,
.bottomBar{
clip-path: inset(0px 0px 0px 0px);
animation: topBar 2s infinite;
}
.middleBar{
clip-path: inset(0px 0px 60px 0px);
animation: middleBar 2s infinite;
animation-delay: 1s;
}
.bottomBar{
clip-path: inset(0px 0px 0px 0px);
animation: bottomBar 2s infinite;
animation-delay: 2s;
}
@keyframes topBar {
0% {
clip-path: inset(0px 26px 0px 0px);
}
50% {
clip-path: inset(0px 0px 0px 0px);
}
100% {
clip-path: inset(0px 26px 0px 0px);
}
}
@keyframes middleBar {
0% {
clip-path: inset(0px 0px 0px 0px);
}
50% {
clip-path: inset(0px 0px 60px 0px);
}
100% {
clip-path: inset(0px 0px 0px 0px);
}
}
@keyframes bottomBar {
0% {
clip-path: inset(0px 26px 0px 0px);
}
50% {
clip-path: inset(0px 0px 0px 0px);
}
100% {
clip-path: inset(0px 26px 0px 0px);
}
}
<svg class="ZLogo" xmlns="http://www.w3.org/2000/svg" width="40" height="56" viewBox="0 0 40 56" fill="none">
<path class="topBar" d="M0 8.90909V0H24.3536L17.9448 8.90909H0Z" fill="black"/>
<path class="middleBar" d="M41.0166 7.63636V0H32.0442L0 48.3636V56H8.97238L41.0166 7.63636Z" fill="black"/>
<path class="bottomBar" d="M17.9448 56L24.3536 48.3636H41.0166V56H17.9448Z" fill="black"/>
</svg>
I would appreciate any assistance in getting the animation to work correctly. Thank you for your help!