23tux
23tux

Reputation: 14736

CSS3 keyframe animation: Set property without animation

I have the following keyframe animation:

@include keyframes(anim1) {
    0% { width: 10%; left: 50%; }
  10% { width: 30%; left: 100%; }
  20% { width: 30%; left: 100%; }
  20% { width: 0%; left: 0%; }
  30% { width: 80%; left: 100%; }
  100% { width: 100%; left: 100%; }
}

At 20% of the animation, the animated div should directly jump to 0% width and 0% left (that's why I set 20% two times), and from that point, the next animations (30% and 100%) should apply. But this doesn't work, my div gets animated form width: 30% -> 0% and left: 100% -> 0%

Is it possible with pure CSS3 animations to "hard set" a divs property to a certain value during a keyframe animation without animating it?

Upvotes: 1

Views: 415

Answers (1)

Veselin
Veselin

Reputation: 287

Try setting your first 20% to 19.99%, so you will have animation like this:

@include keyframes(anim1) {
    0% { width: 10%; left: 50%; }
    10% { width: 30%; left: 100%; }
    19.99% { width: 30%; left: 100%; }
    20% { width: 0%; left: 0%; }
    30% { width: 80%; left: 100%; }
    100% { width: 100%; left: 100%; }
}

In this post @markblythe explains that percentages down to 2 decimal places are possible

Upvotes: 1

Related Questions