7

I wrote a pure css drawing circle animation, but there's a little white space between the two half circles during the animation. (When the animation ends, they gone.)

Can anyone please tell me why does this happened?

My HTML:

.circle__box {
  width: 200px;
  height: 200px;
  margin: 50px auto;
  position: relative;
}

.circle__wrapper {
  width: 100px;
  height: 200px;
  position: absolute;
  top: 0;
  overflow: hidden;
}

.circle__wrapper--right {
  right: 0;
}

.circle__wrapper--left {
  left: 0;
}

.circle__whole {
  width: 160px;
  height: 160px;
  border: 20px solid transparent;
  border-radius: 50%;
  position: absolute;
  top: 0;
  transform: rotate(-135deg);
}

.circle__right {
  border-top: 20px solid teal;
  border-right: 20px solid teal;
  right: 0;
  animation: circleRight 5s linear forwards;
}

.circle__left {
  border-bottom: 20px solid teal;
  border-left: 20px solid teal;
  left: 0;
  animation: circleLeft 5s linear forwards;
}

@keyframes circleRight {
  0% {
    transform: rotate(-135deg);
  }
  50%,
  100% {
    transform: rotate(45deg);
  }
}

@keyframes circleLeft {
  0%,
  50% {
    transform: rotate(-135deg);
  }
  100% {
    -webkit-transform: rotate(45deg);
  }
}
<div class="circle__box">
  <div class="circle__wrapper circle__wrapper--right">
    <div class="circle__whole circle__right"></div>
  </div>
  <div class="circle__wrapper circle__wrapper--left">
    <div class="circle__whole circle__left"></div>
  </div>
</div>

My complete code goes here. Thank you.

Nandita Sharma
  • 13,287
  • 2
  • 22
  • 35
Nicole
  • 125
  • 1
  • 4
  • 11
  • Does this answer your question? [CSS ONLY Animate Draw Circle with border-radius and transparent background](https://stackoverflow.com/questions/26807610/css-only-animate-draw-circle-with-border-radius-and-transparent-background) – Vega Apr 19 '22 at 11:44

2 Answers2

8

Here it is, please check. It was because of you gave .circle-left and .circle-right left:0; and right:0; respectively, change it to left:1px; and right:1px; and you're done...

.circle__box {
  width: 200px;
  height: 200px;
  margin: 50px auto;
  position: relative;
}

.circle__wrapper {
  width: 100px;
  height: 200px;
  position: absolute;
  top: 0;
  overflow: hidden;
}

.circle__wrapper--right {
  right: 0;
}

.circle__wrapper--left {
  left: 0;
}

.circle__whole {
  width: 160px;
  height: 160px;
  border: 20px solid transparent;
  border-radius: 50%;
  position: absolute;
  top: 0;
  transform: rotate(-135deg);
}

.circle__right {
  border-top: 20px solid teal;
  border-right: 20px solid teal;
  right: 1px;
  animation: circleRight 5s linear forwards;
}

.circle__left {
  border-bottom: 20px solid teal;
  border-left: 20px solid teal;
  left: 1px;
  animation: circleLeft 5s linear forwards;
}

@keyframes circleRight {
  0% {
    transform: rotate(-135deg);
  }
  50%,
  100% {
    transform: rotate(45deg);
  }
}

@keyframes circleLeft {
  0%,
  50% {
    transform: rotate(-135deg);
  }
  100% {
    -webkit-transform: rotate(45deg);
  }
}
<div class="circle__box">
  <div class="circle__wrapper circle__wrapper--right">
    <div class="circle__whole circle__right"></div>
  </div>
  <div class="circle__wrapper circle__wrapper--left">
    <div class="circle__whole circle__left"></div>
  </div>
</div>
ElusiveCoder
  • 1,593
  • 1
  • 8
  • 23
  • Okay, but why the two half circles couldn't be cloes together if I didn't set the `left: 1px` and `right: 1px` ? Why they can' t fit in the wrapper? And when I comment out the animations, there're something on the 0deg and 180deg. – Nicole Nov 16 '18 at 07:45
  • After I set the `left: 1px` and `right: 1px` when I zoom in, like 150% or bigger, the white space show up again... – Nicole Nov 16 '18 at 08:21
  • Why you zoom in but? – ElusiveCoder Nov 16 '18 at 08:26
  • This is a project made for the clients. They might do the same as well. – Nicole Nov 16 '18 at 08:41
  • I don't think anybody test project while zoom-in. This is a silly aspect. As i can see, after 150% zoom-in i don't see any white line like you see... – ElusiveCoder Nov 16 '18 at 08:43
  • Would be possible to make it reverse once it completes the circle and loop indefinitely? – MrRobot Dec 13 '19 at 17:43
0

This is my solution:

.circle__wrapper--right { right: 0; margin-right: 20px;}

.circle__wrapper--left { left: 0; margin-left: 20px; }