I've always thought that CSS3 Animations (differently from CSS3 Transitions) once started, always finish the job, no matter if the selector is not matching anymore the element that activated them.
I'm realizing today that I was probably wrong.
In the following example, an animation is triggered by the :focus
and :active
pseudo-classes.
Focus on the first textfield:
- if you press the tab button slowly, you will see the animations starting and ending correctly;
- if you press the tab button quickly, you will see that once a new element get the focus, the old element's animation immediately ends and disappear.
@-webkit-keyframes pressed {
0%, 100% { transform : scale(1); }
50% { transform : scale(2); }
}
@keyframes pressed {
0%, 100% { transform : scale(1); }
50% { transform : scale(2); }
}
a:focus, a:active {
-webkit-animation : pressed 2s;
animation : pressed 2s;
}
a, input {
border : 1px solid silver;
padding : 5px;
height : 40px;
line-height : 28px;
margin : 0px;
display : inline-block;
width : 33.3%;
box-sizing : border-box;
background : white;
vertical-align : middle;
}
a {
color : dodgerBlue;
text-decoration : none;}
input {
color : red;
}
<input type="text" id="foo" value="Start here, then press tab" /><a href = "#">
Lorem
</a><a href = "#">
Ipsum
</a><a href = "#">
dolor
</a><a href = "#">
sit
</a><a href = "#">
amet
</a><a href = "#">
consectetur
</a><a href = "#">
adipiscing
</a><a href = "#">
elit
</a>
I know I can make it end smoothly (on some browser, eg. Firefox yes, Chrome no) by applying:
a { transition: all 2s ease; }
so that if it's loaded up to (for example) 40%, it will animate back from 40% to 0% instead of immediately dropping to 0%.
- I also know that I can use jQuery animations instead of CSS3 animation and make it work that way;
(EDIT: according to the comment, not even jQuery animations will work this way, if I got that right)
What I'm asking here, as a CSS3 Animation newbie, is:
is there a pure CSS3 way to force the animation to run up to 100%, no matter if the initial condition is not valid anymore ?
animationcancel
is implemented. – BoltClocktransition
? I have never seen that prior and it doesn't happen with the snippet for me (in Chrome v38). – Harry