CSS动画-上下移动的Divs之间的动态曲线

时间:2019-01-14 22:53:04

标签: css animation css-animations

我使用CSS动画使点向上和向下移动,但是我想在它们之间绘制一条动态曲线以创建“弯曲图表”类型的外观(图表不是实际的最终目标,只是视觉上的影响)。我将如何实现?这是我目前拥有的:

HTML代码:

<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>

CSS代码:

* {
  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);
  }
}

密码笔: https://codepen.io/anon/pen/JwxJxO

任何帮助都将非常有用,谢谢!

2 个答案:

答案 0 :(得分:0)

您可以使用canvas通过某种动画来实现这一点。

这是我在Codepen上找到的示例,可能对您的问题有用:https://codepen.io/nicolaszamarreno/pen/yXzGgG

答案 1 :(得分:0)

您可以在每个圆圈之间添加线条以模拟这种效果。

这是一个不完美的示例,其中我还使用了偏斜变换来使效果看起来更好(调整不同的值以获得所需的完美结果)

* {
  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>