CSS动画的后续元素延迟

我正在尝试以交错方式将三个点“掉落”到屏幕上,使它们动画化:每个点在视口中的显示都略有延迟。由于某种原因,延迟没有应用到后续元素,它们都立即出现。标记:

  <div class="ellipsis">
    <span>&#x2B24;</span>
    <span>&#x2B24;</span>
    <span>&#x2B24;</span>
  </div>

CSS (nesting courtesy of postcss):

.ellipsis {
  padding: 0;
  margin: 0.33rem 0;
  width: 1rem;
  letter-spacing: 0.23rem;
  animation: fall 1.3s forwards;

  & span {
    display: inline-block;
    font-size: var(--step-0);
  }

  & :nth-child(2) {
    animation-delay: -0.4s;
  }

  & :nth-child(3) {
    animation-delay: -0.7s;
  }
}

@keyframes fall {
  0% {
    transform: translateY(-44px);
  }

  100% {
    transform: translateY(7px);
  }
}

我忘了什么?

评论
kesse
kesse

The animation should be on the <span> elements not the .ellipsis container:

.ellipsis {
  padding: 0;
  margin: 0.33rem 0;
  width: 1rem;
  letter-spacing: 0.23rem;
}

.ellipsis span {
  display: inline-block;
  animation: fall 1.3s forwards;
  transform: translateY(-78px);
  font-size: var(--step-0);
}

.ellipsis span:nth-child(2) {
  animation-delay: 0.7s;
}

.ellipsis span:nth-child(3) {
  animation-delay: 1.4s;
}

@keyframes fall {
  0% {
    transform: translateY(-78px);
  }

  100% {
    transform: translateY(7px);
  }
}
<div class="ellipsis">
  <span>&#x2B24;</span>
  <span>&#x2B24;</span>
  <span>&#x2B24;</span>
</div>
点赞
评论
zex
zex

To animate the dots, not the container, you should add animation: fall 1.3s forwards; to span, not to .ellipsis.

点赞
评论