Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css animation on loader

I have a loader animation but the problem is in the beginning it's like it block before the animation takes place

.loader {
    align-items: center;
    box-sizing: border-box;
    display: flex;
    flex: 1 0 25%;
    flex-direction: column;
    height: 200px;
    justify-content: center;
    max-width: 25%;
}
.ball-scale > div {
  background-color: #fff;
  width: 15px;
  height: 15px;
  border-radius: 100%;
  margin: 2px;
  -webkit-animation-fill-mode: both;
          animation-fill-mode: both;
  display: inline-block;
  height: 60px;
  width: 60px;
  -webkit-animation: ball-scale 1s 0s ease-in-out infinite;
          animation: ball-scale 1s 0s ease-in-out infinite; }

@keyframes ball-scale {
  0% {
    -webkit-transform: scale(0);
            transform: scale(0); }
  100% {
    -webkit-transform: scale(1);
            transform: scale(1);
    opacity: 0; } }

.ball-scale > div {
  background-color: #fff;
  width: 15px;
  height: 15px;
  border-radius: 100%;
  margin: 2px;
  -webkit-animation-fill-mode: both;
          animation-fill-mode: both;
  display: inline-block;
  height: 60px;
  width: 60px;
  -webkit-animation: ball-scale 1s 0s ease-in-out infinite;
          animation: ball-scale 1s 0s ease-in-out infinite; }

.ball-scale-random {
  width: 37px;
  height: 40px; }
  .ball-scale-random > div {
    background-color: black;
    width: 15px;
    height: 15px;
    border-radius: 100%;
    margin: 2px;
    -webkit-animation-fill-mode: both;
            animation-fill-mode: both;
    position: absolute;
    display: inline-block;
    height: 30px;
    width: 30px;
    -webkit-animation: ball-scale 1s 0s ease-in-out infinite;
            animation: ball-scale 1s 0s ease-in-out infinite; }
    .ball-scale-random > div:nth-child(1) {
      margin-left: -7px;
      -webkit-animation: ball-scale 1s 0.2s ease-in-out infinite;
              animation: ball-scale 1s 0.2s ease-in-out infinite; }
    .ball-scale-random > div:nth-child(3) {
      margin-left: -2px;
      margin-top: 9px;
      -webkit-animation: ball-scale 1s 0.5s ease-in-out infinite;
              animation: ball-scale 1s 0.5s ease-in-out infinite; }
<div class="loader">
<div class="loader-inner ball-scale-random">
<div></div>
<div></div>
<div></div>
</div>
</div>

Is there something that I can do to avoid the early beginning effect? And having the animation without the circle blocked in the beginning

like image 529
sonia maklouf Avatar asked Dec 10 '25 06:12

sonia maklouf


1 Answers

Set the initial scale to 0 so that each ball starts out hidden:

.loader {
    align-items: center;
    box-sizing: border-box;
    display: flex;
    flex: 1 0 25%;
    flex-direction: column;
    height: 200px;
    justify-content: center;
    max-width: 25%;
}
.ball-scale > div {
    background-color: #fff;
    width: 15px;
    height: 15px;
    border-radius: 100%;
    margin: 2px;
    -webkit-animation-fill-mode: both;
    animation-fill-mode: both;
    display: inline-block;
    height: 60px;
    width: 60px;
    -webkit-animation: ball-scale 1s 0s ease-in-out infinite;
    animation: ball-scale 1s 0s ease-in-out infinite;
}
@keyframes ball-scale {
    0% {
        -webkit-transform: scale(0);
        transform: scale(0);
    }
    100% {
        -webkit-transform: scale(1);
        transform: scale(1);
        opacity: 0;
    }
}
.ball-scale > div {
    background-color: #fff;
    width: 15px;
    height: 15px;
    border-radius: 100%;
    margin: 2px;
    -webkit-animation-fill-mode: both;
    animation-fill-mode: both;
    display: inline-block;
    height: 60px;
    width: 60px;
    -webkit-animation: ball-scale 1s 0s ease-in-out infinite;
    animation: ball-scale 1s 0s ease-in-out infinite;
}
.ball-scale-random {
    width: 37px;
    height: 40px;
}
.ball-scale-random > div {
    background-color: black;
    width: 15px;
    height: 15px;
    border-radius: 100%;
    margin: 2px;
    -webkit-animation-fill-mode: both;
    animation-fill-mode: both;
    position: absolute;
    display: inline-block;
    height: 30px;
    width: 30px;
    webkit-transform: scale(0);
    transform: scale(0);
    -webkit-animation: ball-scale 1s 0s ease-in-out infinite;
    animation: ball-scale 1s 0s ease-in-out infinite;
}
.ball-scale-random > div:nth-child(1) {
    margin-left: -7px;
    -webkit-animation: ball-scale 1s 0.2s ease-in-out infinite;
    animation: ball-scale 1s 0.2s ease-in-out infinite;
}
.ball-scale-random > div:nth-child(3) {
    margin-left: -2px;
    margin-top: 9px;
    -webkit-animation: ball-scale 1s 0.5s ease-in-out infinite;
    animation: ball-scale 1s 0.5s ease-in-out infinite;
}
<div class="loader">
	<div class="loader-inner ball-scale-random">
		<div></div>
		<div></div>
		<div></div>
	</div>
</div>
like image 164
APAD1 Avatar answered Dec 13 '25 10:12

APAD1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!