Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep styles after animation?

I'm working at a portfolio to show when I apply for my next study. Since we're living in 2012, it has tons of fancy animations and CSS3 junk, just to give them the 'We need this guy' feeling. I'm having a little problem at the moment.

This is a small part of a specific element:

/* This is the CSS of the elements with the id called 'fadein' */ #fadein {     -moz-animation-duration: 2s;     -moz-animation-name: item;     -moz-animation-delay: 4.5s;     -webkit-animation-duration: 5s;     -webkit-animation-name: item; -webkit-animation-delay: 4.5s; opacity:0; -webkit-opacity:0; }  @-webkit-keyframes item { from { -webkit-opacity: 0;      } to {  -webkit-opacity: 1;  } } 

Please note that I left out the Firefox keyframes, since they are quite the same. Right, ugly-formatted CSS that makes elements with the id 'fadein'... fade in.

The problem is, the elements disappear again after the animation is finished. This turns ugly-formatted Css into unusable Css.

Does anybody have any idea how to keep the changed style after the animation?

I guess this question has been asked before and I'm pretty sorry for that if so.

like image 885
amees_me Avatar asked Feb 03 '12 15:02

amees_me


People also ask

How do you make an object stay after animation?

Try turning off the animation looping option in the animation editor. It should be a circular arrow icon that is highlighted blue. It seems you have an animation loop on, you would have to turn it off in order to make it stay in its place, it should be somewhere around the pause/play button, you won't miss it.

How do I animate persist in CSS?

Use animation-fill-mode: forwards; The element will retain the style values that is set by the last keyframe (depends on animation-direction and animation-iteration-count).


2 Answers

Try with:

#fadein {   -webkit-animation-fill-mode: forwards; /* Chrome 16+, Safari 4+ */   -moz-animation-fill-mode: forwards;    /* FF 5+ */   -o-animation-fill-mode: forwards;      /* Not implemented yet */   -ms-animation-fill-mode: forwards;     /* IE 10+ */   animation-fill-mode: forwards;         /* When the spec is finished */ } 
like image 92
methodofaction Avatar answered Sep 23 '22 04:09

methodofaction


Duopixels answer is the right way, but not totally cross-browser, however, this jquery plugin enables animation callbacks and you can style the elements how you like in the callback function: https://github.com/krazyjakee/jQuery-Keyframes

like image 33
Jake Cattrall Avatar answered Sep 24 '22 04:09

Jake Cattrall