html – Sequential delay on Sass for child elements?

Question:

Hello everyone! How can I use Sass to convert this into a more elegant solution for incrementing the transition-delay on child elements?

Here, so that, as in the ZOE example, icons of social networks are consistently shown. An example is the Zoe clause .

.myClass {
  &:nth-child(1) {
    transition: all 1s ease-out 0.5s;
  }
  &:nth-child(2) {
    transition: all 1s ease-out 0.7s;
  }
  &:nth-child(3) {
    transition: all 1s ease-out 0.9s;
  }
  &:nth-child(4) {
    transition: all 1s ease-out 1.1s;
  }
  &:nth-child(5) {
    transition: all 1s ease-out 1.3s;
  }
}

Answer:

Sass has a control directive – @for . It can be used for such tasks. (Working example on Codepen.io ).

Sass :

//Создаём переменные для управления значениями
$items: 4
$transition: 500ms

//Каждому элементу будет прибавлять по 0.060s
@for $i from 0 through $items 
  &:nth-child(#{$i + 1}) 
    transition-delay: $transition+(60ms*($i))

Compiled version:

* {
  margin: 0;
  padding: 0;
}

.wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.wrapper:hover .item {
  transform: translateY(50px);
  background-color: crimson;
}

.item {
  width: 100px;
  height: 100px;
  background-color: tomato;
  transition: 500ms;
}

.item:nth-child(1) {
  transition-delay: 500ms;
}

.item:nth-child(2) {
  transition-delay: 560ms;
}

.item:nth-child(3) {
  transition-delay: 620ms;
}

.item:nth-child(4) {
  transition-delay: 680ms;
}

.item:nth-child(5) {
  transition-delay: 740ms;
}
<div class="wrapper">
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
</div>
Scroll to Top