在nth-child()中创建更高的延迟?

时间:2015-12-24 10:13:50

标签: html css css3 css-selectors

我正在尝试做一个小清单。该清单应该连续弹出。因此,第一个点首先出现,然后是第二点,依此类推。

所以我尝试了这个(重要的一点是:CSS中的nth-child()):

.animated {
  -webkit-animation-duration: 0.8s;
  animation-duration: 0.8s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
  -webkit-animation-timing-function: ease-out;
  animation-timing-function: ease-out;
}
.animated:nth-child(2) {
  animation-delay: 1s
}
.animated:nth-child(3) {
  animation-delay: 2s
}
.animated:nth-child(4) {
  animation-delay: 3s
}
@-webkit-keyframes fadeInUp {
  0% {
    opacity: 0;
    -webkit-transform: translateY(20px);
  }
  100% {
    opacity: 1;
    -webkit-transform: translateY(0);
  }
}
@keyframes fadeInUp {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}
.fadeInUp {
  -webkit-animation-name: fadeInUp;
  animation-name: fadeInUp;
}
.checklist_table {
  border-radius: 10px;
  padding: 10px;
  background: #eee;
  margin: 0 auto;
  width: 80%;
}
.checklist_table tr {
  width: 100%;
}
.checklist_table td {
  padding: 10px;
  width: 20%;
  text-align: center;
}
.checklist_table td:nth-child(2) {
  padding: 10px;
  width: 80%;
  text-align: left;
}
<table class="checklist_table">
  <tr>
    <td>
      <img src="checkmark.png" width="50px" class="animated fadeInUp" />
    </td>

    <td>
      <p class="status_checklist_p">1</p>
    </td>
  </tr>
  <tr>
    <td>
      <img src="checkmark.png" class="animated fadeInUp" width="50px" />
    </td>

    <td>
      <p class="status_checklist_p">2</p>
    </td>
  </tr>
  <tr>
    <td>
      <img src="checkmark.png" class="animated fadeInUp" width="50px" />
    </td>

    <td>
      <p class="status_checklist_p">3</p>
    </td>
  </tr>
</table>

Fiddle Demo

现在动画有效。然而不是延迟。

我在这里做错了什么?

1 个答案:

答案 0 :(得分:2)

动画延迟无效,因为这些选择器当前不会选择任何元素。每个带有img的{​​{1}}元素是其父class='animated'的第一个也是唯一的子元素,这就是选择器不选择任何内容的原因。

您应该根据td元素的子索引应用选择器。

&#13;
&#13;
tr
&#13;
.animated {
  -webkit-animation-duration: 0.8s;
  animation-duration: 0.8s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
  -webkit-animation-timing-function: ease-out;
  animation-timing-function: ease-out;
}
tr:nth-child(2) .animated {
  animation-delay: 1s
}
tr:nth-child(3) .animated {
  animation-delay: 2s
}
.animated:nth-child(4) {
  animation-delay: 3s
}
@-webkit-keyframes fadeInUp {
  0% {
    opacity: 0;
    -webkit-transform: translateY(20px);
  }
  100% {
    opacity: 1;
    -webkit-transform: translateY(0);
  }
}
@keyframes fadeInUp {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}
.fadeInUp {
  -webkit-animation-name: fadeInUp;
  animation-name: fadeInUp;
}
.checklist_table {
  border-radius: 10px;
  padding: 10px;
  background: #eee;
  margin: 0 auto;
  width: 80%;
}
.checklist_table tr {
  width: 100%;
}
.checklist_table td {
  padding: 10px;
  width: 20%;
  text-align: center;
}
.checklist_table td:nth-child(2) {
  padding: 10px;
  width: 80%;
  text-align: left;
}
&#13;
&#13;
&#13;