How to Delay the Start of a CSS Animation

CSS animation-delay not making a delay before animation start

You are overwriting your animation-delay: 2s; with the animation shorthand rule underneath.

Move the animation-delay after the animation rule like this:

h1.type-animation {
width: 10ch;
animation: cursor .5s step-end infinite alternate,
type 1.5s steps(10, end);
animation-delay: 2s;
}

and the delay will work, as you can see in this snippet:

.type-animation {
box-shadow: .6em 0 0 #00CCC7;
overflow: hidden;
white-space: nowrap;
}

h1.type-animation {
width: 10ch;
animation: cursor .5s step-end infinite alternate,
type 1.5s steps(10, end);
animation-delay: 2s;
}


@keyframes type {
0% {
width: 0;
}
}

@keyframes cursor {
50% {
box-shadow: .6em 0 0 transparent;
}
}
<body>
<h1 class="type-animation">A Website.</h1>
</body>

CSS: animation delay on only one animation

I added a delay of 4 secs to the final animation below. For visibility purpose, I set the duration of each animation to 2 secs.

div {  width: 200px;  height: 200px;  opacity: 0.3;  background-color: darkgray;  animation:2000ms radius-in forwards, 2000ms opacity-in forwards, 2000ms 4000ms opacity-out forwards;}
@keyframes radius-in {from { border-radius: 0; }to { border-radius: 25px; }}
@keyframes opacity-in {from { opacity: 0; }to { opacity: 1; }}
@keyframes opacity-out {from { opacity: 1; }to { opacity: 0.3; }}
<div></div>

CSS animation with delay and opacity

Just don't set the initial opacity on the element itself, set it within the @keyframes:

#element{
-webkit-animation: 3s ease 0s normal forwards 1 fadein;
animation: 3s ease 0s normal forwards 1 fadein;
}

@keyframes fadein{
0% { opacity:0; }
66% { opacity:0; }
100% { opacity:1; }
}

@-webkit-keyframes fadein{
0% { opacity:0; }
66% { opacity:0; }
100% { opacity:1; }
}

This technique takes the delay off of the animation, so that it starts running immediately. However, the opacity won't really change until about 66% into the animation. Because the animation runs for 3 seconds, it gives the effect of a delay for 2 seconds and fade in for 1 second.

See working example here: https://jsfiddle.net/75mhnaLt/

You might also want to look at using conditional comments for older browsers; IE8 and IE9.

Something like the following in your HTML:

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en-GB"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8 ie-7" lang="en-GB"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9 ie-8" lang="en-GB"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en-GB"> <!--<![endif]-->

You could then do something like:

.lt-ie9 #element {
opacity: 1;
}

CSS | Delay each individual animation by 2 seconds

.text-container{width: 100%;font-size: 14px;
height: 20px;
background:#c03022;
color:#fff;
}

.dynamic-text{
list-style: none;
position: absolute;
overflow: hidden;
height: 20px;
margin: 0 auto;
left: 0;
right: 0;
width: 100%;
}

.item{
position: relative;
top: 0;
animation: move 10s infinite;
width: 100%;
text-align:center;
}


@keyframes move{
0% {
top: 0px;
}
10% {
top: 0px;
}
20% {
top: -33px;
}
30% {
top: -33px;
}
40% {
top: -33px;
}
50% {
top: -66px;
}
60% {
top: -66px;
}
70% {
top: -66px;
}
80% {
top: -100px;
}
90% {
top: -100px;
}
100% {
top: -100px;
}
}
<div class="text-container">
<ul class="dynamic-text">
<li class="item">Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
<li class="item"> </li>
<li class="item">Sed ut perspiciatis unde omnis iste natus error sit voluptatem</li>
<li class="item"> </li>
<li class="item">But I must explain to you how all this mistaken idea of denouncing</li>
<li class="item"> </li>
<li class="item">At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis</li>
</ul>
</div>

Delay Animation with CSS only

Need to keep the same transform of couple of moment then trigger next. Please follow the code below and you will understand what I mean.

.im {
float: left;
margin-right: 0.3em;
}

.im-wrapper {
display: flex;
height: 1.1em;
}

.im-items {
overflow: hidden;
}

.im-item {
display: block;
height: 100%;
color: $primary;
animation: move 10s infinite;
animation-delay: 1s;
white-space: nowrap;
}

/* Here is the different */
@keyframes move {
0% {
transform: translateY(0%);
}
10% {
transform: translateY(-100%);
}
20% {
transform: translateY(-100%);
}
30% {
transform: translateY(-200%);
}
40% {
transform: translateY(-200%);
}
50% {
transform: translateY(-300%);
}
60% {
transform: translateY(-300%);
}
70% {
transform: translateY(-400%);
}
80% {
transform: translateY(-400%);
}
90% {
transform: translateY(0%);
}
100% {
transform: translateY(0%);
}
}
<div class="hero-top-title">
<div style="display: inline-block;">
<div>Hi</div>
</div>, I'm
<div style="display: inline-block;">
<div>A Person</div>
</div>.
<br>
<div class="im">Am I a</div>
<div class="im-wrapper">
<div class="im-items">
<div class="im-item im-item1">Father</div>
<div class="im-item im-item2">Mother</div>
<div class="im-item im-item3">Brother</div>
<div class="im-item im-item4">Sister</div>
<div class="im-item im-item5">Grandma</div>
</div>
<div>?</div>
</div>
</div>

CSS Animation Timing Issue on Delay

You have one animation that runs evert 2 seconds and another one that runs for 2.1 seconds, of course they won't sync.
What you can do is set the delay in the keyframes, so instead of 0% it will start in a different value.

For example:

.container {
position: relative;
width: 100px;
height: 100px;
background: pink;
border-radius: 50%;
margin: 50px auto;
animation: containerAnimation 2s infinite;
}

.animated-border {
position: absolute;
left: 0;
width: 97px;
height: 97px;
border: 2px solid;
border-radius: 50%;
animation: borderAnimation 2s infinite;
}

@keyframes containerAnimation {

0% {
transform: scale3d(0.9, 0.9, 1); // I've changed it to be more noticable.
}

5% {
transform: scale3d(1.05, 1.05, 1);
}

100% {
transform: scale3d(1.05, 1.05, 1);
}
}

@keyframes borderAnimation {
5% { // Start from here instead from 0%.
transform: scale3d(1, 1, 1);
opacity: 1;
}

100% {
transform: scale3d(2, 2, 1);
opacity: 0;
}
}
<div class="container">
<div class="animated-border"></div>
</div>

CSS animation delay in between loop

Make your loop longer and add more keyframes.

@-webkit-keyframes slidingPrice {
0% { opacity: 0; bottom: -30px; } /* 0ms initial values */
2.38% { opacity: 1; bottom: 0; } /* 150ms half of animation */
34.13% { opacity: 1; bottom: 0; } /* 2150ms still at half of animation */
36.51% { opacity: 0; bottom: -30px; } /* 2300ms back to initial */
100% { opacity: 0; bottom: -30px; } /* 6300ms still at initial */
}

.price {
-webkit-animation-name: slidingPrice;
-webkit-animation-duration: 6300ms;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-delay: 4s;
}

How can I increase the delay between my infinite lopping CSS animation?

When setting animation-iteration-count to infinite, the animation will repeat forever. There is no native way to increment the time between two iterations.

You can, however, increase the time in between the moment the element starts being "animated" and the effective start of the animation, by setting animation-delay property. But this delay is only applied before the first iteration, not in between consecutive iterations.

To achieve your desired result you have two methods:

  • modify the animation so that the delay you want is contained within the animation loop (this is the most common way to do it). With this technique, the pause is set to a percentage of the entire animation iteration so you can't decouple the speed of the animation from the time between actual element animations.
  • apply the animation using a class and write a small script which applies and removes that class at the appropriate times. This technique has the advantage of decoupling the duration of the animation from the time between applications and it's useful especially if the animation-iteration-count is set to 1. Also note using this technique animation-delay applies each time you apply the class, if you have set it to a valid truthy value.

Technically, there would be a third way, which would be to set the animation-play-state to running/paused, using JavaScript, at the appropriate times, similarly to the second method. But, in practice, if for any reason this goes out of sync with the actual animation, it might get to the point where it pauses the animation mid-way in the actual animation, resulting in a "buggy" behavior, from the user's perspective so option 2 above should always be preferred to this, technically possible, third method.



Related Topics



Leave a reply



Submit