K
K
Kerhin2019-06-20 16:19:33
css
Kerhin, 2019-06-20 16:19:33

How to add 2 classes in turn (React)?

I want to implement a function that, when clicked, adds several classes to an element, but does it not all at once, but each class in turn (that is, with a time interval).
I roughly understand how to do this, I use special conditions for if using setTime, but so far, unfortunately, I have not reached the desired result.
Example:
There is an element with class .block

<div>
  <div className="block">
</div>

and let's say 2 classes .first and .second
.block {
  position: absolute;
  top: 0;
  width: 50px;
  height: 20px;
  background-color: #fff;
  border-radius: 10px;
  transition: all .5s;
}

.first {
  top: 60px;
}
.second {
  transform: rotate(45deg);
}

when clicking on an element with the .block class , the .first class would be added first , and then, after 3 seconds, the .second class would be added

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-06-20
@Kerhin

For this kind of tasks, there is @keyframes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question