0

How can I use setinterval() for css animation?

For example, in the example below, I want the div to come with animation after 3000ms. How do I do this?

Can I get it starting from bottom 0, like the price segment that changes when I choose the minute and day as on this page?

<div><span>$</span>2.000</div>

jsfiddle example

div {
  font-size: 42px;
  position: relative;
  animation: mymove 0.3s;
  animation-timing-function: ease-in-out;
}
div span{
    font-size: 24px;
    padding-right: 5px;
}


@keyframes mymove {
  0% {
    bottom: -70px;
    }
  100% {
    bottom: 0px;
    }
}

1 Answers1

1

Set an animation-delay, together with animation-fill-mode:forwards to prevent the div from reverting to the initial state when the animation has finished. You can use opacity to control when to show the element (I've used a dark body background here so that your white text is visible):

body {
  background: #333;
  color: #fff;
}

.wrapper {
  overflow: hidden;
}

.wrapper div {
  font-size: 42px;
  position: relative;
  animation: mymove 0.3s;
  animation-timing-function: ease-in-out;
  animation-delay: 3s;
  animation-fill-mode: forwards;
  opacity: 0;
}

.wrapper div span {
  font-size: 24px;
  padding-right: 5px;
}

@keyframes mymove {
  0% {
    opacity: 1;
    display: block;
    transform: translateY(-70px);
  }
  100% {
    opacity: 1;
    display: block;
    transform: translateY(0px);
  }
}
<div class="wrapper">
  <div><span>$</span>2.000</div>
</div>
Wais Kamal
  • 5,858
  • 2
  • 17
  • 36