Alexzander Flores
Alexzander Flores

Reputation: 209

CSS Animations - Dynamic Curved Lines Between Divs That Move Up & Down

I have dots moving up and down with a CSS animation, however I'd like to draw a dynamic curved line between them to create "Curved Chart" type look (a chart isn't the actual end goal, just the visual effect). How would I achieve this? Here's what I currently have:

The HTML Code:

<ul>
    <li><span class="ball1"></span></li>
    <li><span class="ball2"></span></li>
    <li><span class="ball3"></span></li>
    <li><span class="ball4"></span></li>
    <li><span class="ball5"></span></li>
    <li><span class="ball6"></span></li>
    <li><span class="ball7"></span></li>
    <li><span class="ball8"></span></li>
    <li><span class="ball9"></span></li>
    <li><span class="ball10"></span></li>
</ul>

The CSS Code:

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: white;
}
ul {
  width: 340px;
  height: 80px;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
}
li {
  display: flex;
  justify-content: center;
  position: relative;
}
li:before {
  content: '';
  width: 6px;
  height: 90px;
  position: absolute;
  top: -5px;
  border-radius: 90px;
}
span {
  width: 20px;
  height: 20px;
  background: blue;
  border-radius: 50%;
  box-shadow: 0 0 20px -5px rgba(0, 0, 0, 0.3);
  display: block;
  animation: move 3s ease-in-out infinite alternate;
}
span.ball1 {
  animation-delay: 0.25s;
}
span.ball2 {
  animation-delay: 0.5s;
}
span.ball3 {
  animation-delay: 0.75s;
}
span.ball4 {
  animation-delay: 1s;
}
span.ball5 {
  animation-delay: 1.25s;
}
span.ball6 {
  animation-delay: 1.5s;
}
span.ball7 {
  animation-delay: 1.75s;
}
span.ball8 {
  animation-delay: 2s;
}
span.ball9 {
  animation-delay: 2.25s;
}
span.ball10 {
  animation-delay: 2.5s;
}
@keyframes move {
  100% {
    transform: translateY(58px);
  }
}

Code Pen: https://codepen.io/anon/pen/JwxJxO

Any help would be super useful, thank you!

Upvotes: 0

Views: 2235

Answers (2)

Temani Afif
Temani Afif

Reputation: 272807

You can add line between each circle to simulate such effect.

Here is a non-perfect example where I also used skew transformation to make the effect looks better (adjust the different value to get a perfect result like you want)

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: white;
}
ul {
  width: 340px;
  height: 80px;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
}
li {
  display: flex;
  justify-content: center;
  position: relative;
}
span {
  width: 20px;
  height: 20px;
  background: blue;
  border-radius: 50%;
  box-shadow: 0 0 20px -5px rgba(0, 0, 0, 0.3);
  display: block;
  animation: move 3s ease-in-out infinite alternate;
  position:relative;
    transform: translateY(-29px);
}
li:not(:last-child) span::before {
  content:"";
  position:absolute;
  top:50%;
  left:100%;
  width:20px;
  height:2px;
  background:blue;
  animation-delay:inherit;
  animation: skew 3s ease-in-out infinite alternate;
}
span.ball1 {
  animation-delay: 0.25s;
}
span.ball2 {
  animation-delay: 0.5s;
}
span.ball3 {
  animation-delay: 0.75s;
}
span.ball4 {
  animation-delay: 1s;
}
span.ball5 {
  animation-delay: 1.25s;
}
span.ball6 {
  animation-delay: 1.5s;
}
span.ball7 {
  animation-delay: 1.75s;
}
span.ball8 {
  animation-delay: 2s;
}
span.ball9 {
  animation-delay: 2.25s;
}
span.ball10 {
  animation-delay: 2.5s;
}
@keyframes move {
  0% {
    transform: translateY(-29px);
  }
  100% {
    transform: translateY(29px);
  }
}
@keyframes skew {
  0% {
    transform: skewY(13deg);
  }
  30% {
    transform: skewY(10deg);
  }
  70% {
    transform: skewY(-10deg);
  }
  100% {
    transform: skewY(-13deg);
  }
}
<ul>
    <li><span class="ball1"></span></li>
    <li><span class="ball2"></span></li>
    <li><span class="ball3"></span></li>
    <li><span class="ball4"></span></li>
    <li><span class="ball5"></span></li>
    <li><span class="ball6"></span></li>
    <li><span class="ball7"></span></li>
    <li><span class="ball8"></span></li>
    <li><span class="ball9"></span></li>
    <li><span class="ball10"></span></li>
</ul>

Upvotes: 1

jcal
jcal

Reputation: 875

You can achieve this with kind of animations with canvas.

here's an example I found on codepen, which might be useful for your problem: https://codepen.io/nicolaszamarreno/pen/yXzGgG

Upvotes: 0

Related Questions