CSS Infinite Loop issue

Viewed 202

I am happy with the current animation but Im having trouble getting the animation to start over from the beginning and looping infinitely. Can use some help on this one.I have also included the svg as well.I believe that the issue may be related to the forwards keyword as the animation runs sequentially from bar 1 to bar 7. Thanks again for the help as this has been a bit of a concern for a while now.

body {
  background: #000;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

svg g path {
  opacity: 0;
  animation: fadeIn 1s ease-in-out 300ms forwards;
}

svg g path#bar1 {
  animation-delay: 500ms;
}

svg g path#bar2 {
  animation-delay: 1s;
}

svg g path#bar3 {
  animation-delay: 2s;
}

svg g path#bar4 {
  animation-delay: 3s;
}

svg g path#bar5 {
  animation-delay: 4s;
}

svg g path#bar6 {
  animation-delay: 5s;
}

svg g path#bar7 {
  animation-delay: 6s;
}
<svg width="40pt" height="40pt" viewBox="0 0 236 202" fill="none" xmlns="http://www.w3.org/2000/svg">
        <g>
            <g id="Group 2">
                <g id="Group 1">
                    <g id="surface1">
                        <g id="Group">
                            <path id="bar7" d="M236 32.6488L214.5 5L193 32.6488H204.579V192.693H223.897V32.6488H236Z"
                                fill="white" />
                        </g>
                        <g id="Group_2">
                            <path id="bar6" d="M172 56V192.645H193.404V56H172Z" fill="white" />
                        </g>
                        <g id="Group_3">
                            <path id="bar5" d="M139 76V192.504H159.404V76H139Z" fill="white" />
                        </g>
                        <g id="Group_4">
                            <path id="bar4" d="M106 89V192.363H126.404V89H106Z" fill="white" />
                        </g>
                        <g id="Group_5">
                            <path id="bar3" d="M75 112V191.957H96.4042V112H75Z" fill="white" />
                        </g>
                        <g id="Group_6">
                            <path id="bar2" d="M43 130V192.957H64.4042V130H43Z" fill="white" />
                        </g>
                        <path id="bar1" d="M11 149V191.957H31V149H11Z" fill="white" />
                    </g>
                </g>
            </g>
        </g>
    </svg>

3 Answers

Check this out

@keyframes fadeIn {
     0% {
         opacity: 0;
    }

  50%{
    opacity:1
  }
     100% {
         opacity:0;
    }
}
 body {
     background: #444;
}
 path[class^="bar"] {
     opacity: 0;
     animation: fadeIn 5s ease;
   animation-iteration-count: 10;
}

 path.bar1 {
     animation-delay: 500ms;
}
 path.bar2 {
     animation-delay: 1s;
}
 path.bar3 {
     animation-delay: 1.5s;
}
 path.bar4 {
     animation-delay: 2s;
}
 path.bar5 {
     animation-delay: 2.5s;
}
 path.bar6 {
     animation-delay: 3s;
}
 path.bar7 {
     animation-delay: 3.5s;
}
 
<body>
<svg width="40pt" height="40pt" viewBox="0 0 236 202" fill="none" xmlns="http://www.w3.org/2000/svg">
        <g>
            <g id="Group 2">
                <g id="Group 1">
                    <g id="surface1">
                        <g id="Group">
                            <path class="bar7" d="M236 32.6488L214.5 5L193 32.6488H204.579V192.693H223.897V32.6488H236Z"
                                fill="white" />
                        </g>
                        <g id="Group_2">
                            <path class="bar6" d="M172 56V192.645H193.404V56H172Z" fill="white" />
                        </g>
                        <g id="Group_3">
                            <path class="bar5" d="M139 76V192.504H159.404V76H139Z" fill="white" />
                        </g>
                        <g id="Group_4">
                            <path class="bar4" d="M106 89V192.363H126.404V89H106Z" fill="white" />
                        </g>
                        <g id="Group_5">
                            <path class="bar3" d="M75 112V191.957H96.4042V112H75Z" fill="white" />
                        </g>
                        <g id="Group_6">
                            <path class="bar2" d="M43 130V192.957H64.4042V130H43Z" fill="white" />
                        </g>
                        <path class="bar1" d="M11 149V191.957H31V149H11Z" fill="white" />
                    </g>
                </g>
            </g>
        </g>
    </svg>
  </body>

The animation-iteration-count CSS property sets the number of times an animation sequence should be played before stopping. Add the following to your svg g path CSS selector function animnation-iteration-count: infinite.

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

svg g rect {
  opacity: 0;

  animation: fadeIn 1s ease-in-out 300ms infinite;

  &#bar1 {
    animation-delay: 500ms;
  }
  &#bar2 {
    animation-delay: 1s;
  }
  &#bar3 {
    animation-delay: 2s;
  }
  &#bar4 {
    animation-delay: 3s;
  }
  &#bar5 {
    animation-delay: 4s;
  }
  &#bar6 {
    animation-delay: 5s;
  }
  &#bar7 {
    animation-delay: 6s;
  }
}
<svg><g>
<rect fill="#bb22930" width="100" height="100"></rect>
</g></svg>

Related