FadeOut/FadeIn animations before/after ngAnimate - css

I have this form on plunker and a struggling with adding a fade animation.
What I want to do is, before the keyframe animation starts have the content fade out. And when the new view appears, I want the the keyframe animation to finish and than an animate.css animation to run (fadeInUp for example).
So the view will animate and then the content inside the view will animate, If somebody can help me with this I would really appreciate it.
my current animation is using the following keyframe animation:
#-webkit-keyframes slideOutLeft {
0% {
transform: scaleY(1) scaleX(1);
}
20% {
transform: scaleY(0.01) scaleX(1);
}
40% {
transform: scaleY(0.005) scaleX(0.5);
}
50% {
opacity: 1;
}
100% {
transform: scaleY(0.005) scaleX(0.5);
opacity: 0;
}
}
#-webkit-keyframes slideInRight {
0% {
transform: scaleY(0.005) scaleX(0.5);
background: rgba(0,188,140,1);
opacity: 0;
}
50% {
transform: scaleY(0.005) scaleX(0.5);
background: rgba(0,188,140,1);
z-index: 1;
opacity: 0;
}
70% {
transform: scaleY(0.005) scaleX(1);
background: rgba(0,188,140,1);
opacity: 1;
}
100% {
transform: scaleY(1) scaleX(1);
}
}
Running on ng.enter and ng.leave
/* enter animation */
#form-views.ng-enter {
-webkit-animation:slideInRight 2s both ease;
-moz-animation:slideInRight 2s both ease;
animation:slideInRight 2s both ease;
}
/* leave animation */
#form-views.ng-leave {
-webkit-animation:slideOutLeft 2s both ease;
-moz-animation:slideOutLeft 2s both ease;
animation:slideOutLeft 2s both ease;
}
EDIT 1:
I have updated the code here
using:
#form-views.ng-enter * {
-webkit-animation:fadeIn 2s both ease 3s;
-moz-animation:fadeIn 2s both ease 3s;
animation:fadeIn 2s both ease 3s;
}
#form-views.ng-leave * {
-webkit-animation:fadeOut 0.5s both ease;
-moz-animation:fadeOut 0.5s both ease;
animation:fadeOut 0.5s both ease;
}
And this is the animation:
#keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
#keyframes fadeOut { from { opacity:1; } to { opacity:0; } }
The code appears and disappearing at the correct time but doesn't animate the opacity.

I would try adding separate animation for fadeIn/Out and using the css animation delay to trigger one after the other. E.G:
/* enter animation */
#form-views.ng-enter {
-webkit-animation:slideInRight 2s both ease, fadeIn 1s both ease 2s;
-moz-animation:slideInRight 2s both ease, fadeIn 1s both ease 2s;
animation:slideInRight 2s both ease, fadeIn 1s both ease 2s;
}
/* leave animation */
#form-views.ng-leave {
-webkit-animation:slideOutLeft 2s both ease 1s, fadeOut 1s both ease;
-moz-animation:slideOutLeft 2s both ease 1s, fadeOut 1s both ease;
animation:slideOutLeft 2s both ease 1s, fadeOut 1s both ease;
}
and i think you know what the fadeIn and fadeOut animations should be.
UPDATE:
Here's a plunker with the code working the way I believe you want it to work. In chrome at least. You'll need to use the correct prefixes/no prefixes to get it working in other browsers.

Related

How do I rotate an image at hover and every 10 seconds?

I made a css that can rotate my image when someone hover it
But I would rotate this image every 10 seconds too
.smiley-construct {
width: 64px;
padding: 0;
}
.smiley-construct img {
transition: 0.70s ease-in-out;
-webkit-transition: 0.70s;
-moz-transition: 0.70s;
-ms-transition: 0.70s;
-o-transition: 0.70s;
}
.smiley-construct img:hover {
transition: 0.70s ease-in-out;
-webkit-transition: 0.70s;
-moz-transition: 0.70s;
-ms-transition: 0.70s;
-o-transition: 0.70s;
transform: rotate(540deg);
-webkit-transform: rotate(540deg);
-moz-transform: rotate(540deg);
-o-transform: rotate(540deg);
-ms-transform: rotate(540deg);
}
<div class="smiley-construct">
<img src="https://quentinrenaux.com/wp-content/themes/quentinrenaux-V2.01.2021/img/smile/smile.png">
</div>
Can I change that to rotate my image every 10 seconds
but and keep the hover rotate too ?
Thanks
You can create a keyframe in css, something like this:
#keyframes rotating {
0% {
transform: rotate(0deg);
}
93% {
transform: rotate(0deg);
}
100% {
transform: rotate(540deg);
}
.smiley-construct img {
animation: rotating 10s infinite;
transition: 0.70s ease-in-out;
-webkit-transition: 0.70s;
-moz-transition: 0.70s;
-ms-transition: 0.70s;
-o-transition: 0.70s;
}
We can have two CSS animations - one which rotates the face then waits for the best part of 10s and keeps doing that and the other which kicks in on hover and just spins once.
I am not absolutely sure of the effect you want - is the face to go upside down after each rotate? You may want to play around with animation-fill-mode if not.
Here is a snippet:
.smiley-construct {
width: 64px;
padding: 0;
}
.smiley-construct img {
animation-name: spinwait;
animation-duration: 10s;
animation-iteration-count: infinite;
}
.smiley-construct img:hover {
animation-name: spin;
animation-duration: 0.7s;
animation-iteration-count: 1;
}
#keyframes spinwait {
0% {
transform: rotate(0deg);
}
7% {
transform: rotate(540deg);
}
7.1% {
transform: rotate(0deg);
}
100% {
transform: rotate(0deg);
}
}
#keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(540deg);
}
}
<div class="smiley-construct">
<img src="https://quentinrenaux.com/wp-content/themes/quentinrenaux-V2.01.2021/img/smile/smile.png">
</div>
You can make a function in javascript and make something like this:
Or make it jquery on when your page loads, but without knowing the structure and the resources available, I can not decide for you.
var elemPicture = document.getElementById("PictureId");
elemPicture.style.transition = "all 0.5s";
elemPicture.style.transform = "rotate(15deg)";
Better yet, use keyframes. No need to add extra JS if you can use CSS.
There's a pretty good explanation of how to do this here.

CSS animation forwards is preventing css transitions

I am setting my CSS animation type to forwards so that the finished frame of the animation is the default state when finished.
But now, the transition that animates the same property (transform) is not working anymore...
I have to use forwards because otherwise the opacity resets to 0 after animating.
How can I enable a transition as soon as an animation has finished? I am looking for a CSS-only option without javascript.
CSS
album {
opacity: 0;
animation:movein 0.6s forwards;
transition: all 0.3s ease-in-out;
}
album:hover {
transform:scale(1.05); // this doesn't work
box-shadow: 0px 0px 45px rgba(0,0,0,0.5); // this works
}
#keyframes movein {
from {
opacity:0;
transform: translateX(-100px);
}
to {
opacity:1;
transform: translateX(0px);
}
}
album:nth-child(2) {
animation-delay: 0.2s; // delay keeps opacity 0 for a while
}
album:nth-child(3) {
animation-delay: 0.4s; // delay keeps opacity 0 for a while
}
One solution could be to split up your animation. Only the fadein animation has animation forwards.
album {
opacity: 0;
animation:movein 0.6s, fadein 0.6s forwards;
transition: all 0.3s ease-in-out;
}
#keyframes movein {
from {
transform: translateX(-100px);
}
to {
transform: translateX(0);
}
}
#keyframes fadein {
from {
opacity:0;
}
to {
opacity:1;
}
}

Restart CSS3 Animation without javascript?

Is it possible to "restart" a keyframe animation after it's stops with the same animation delay time again?
#keyframes scale {
50% { transform: scale(1.2); }
100% { transform: scale(1); }
}
.animated-btn {
animation: scale ease-in 1;
animation-fill-mode:forwards;
animation-duration: .6s;
animation-delay: 11.8s;
}
<a href="" class="btn btn__arrow animated-btn">
Aniamted Button
</a>
Unfortunately it's not possible to set a delay before each animation, but you can set a delay inside the animation. Just let the animation do nothing for a while until you reach a certain percentage.
Here's the updated code.
#keyFrames scale {
90% {
transform: scale(1)
}
95% {
transform: scale(1.3)
}
100% {
transform: scale(1);
}
}
.animated-btn {
display: inline-block;
animation: scale ease-in 1;
animation-fill-mode: forwards;
animation-duration: 12.4s;
animation-delay: 0s;
animation-iteration-count: infinite;
/* Or the shorthand:
animation: scale 1.4s 0s infinite ease-in forwards;
*/
}
Yes you just need to use the animation-iteration-count property.
You can set its value to infinite.

Adding an opacity change and a transform in CSS

How do I combine these two animations (translate & buttonFade) so that they both affect the same image ? Both animations work seperatley but not together. Is there a way to combine the two? (I have omitted the -moz- , -o- etc purposefully to make it easier to read, I have tried adding these and it makes no difference)
translate {
-webkit-animation: moveLeft 1s forwards;
}
#-webkit-keyframes moveLeft {
0% {-webkit-transform: translateX(0px)}
100% {-webkit-transform: translateX(100px)}
}
.intro-button{
position:absolute;
top: 350px;
left: 625px;
opacity: 0;
-webkit-animation: buttonFade 3s 1 forwards;
-webkit-animation-delay: 2s;
}
#-webkit-keyframes buttonFade {
0% {opacity: 0;}
80% {opacity: 0;}
100% {opacity: 1;}
}
Any help would be much appreciated!
You can list multiple animations by separating them with a comma, as such you can simply call moveLeft from your CSS for .intro-button and remove your CSS for translate (which by the way is not a valid selector).
You'll also want to add a other value for the animation delay, which should be first animation delay + first animation duration (4s)
Demo Fiddle
Change your CSS thusly:
#-webkit-keyframes moveLeft {
0% {
-webkit-transform: translateX(0px)
}
100% {
-webkit-transform: translateX(100px)
}
}
.intro-button {
position:absolute;
top: 350px;
left: 625px;
opacity: 0;
-webkit-animation: buttonFade 3s 1 forwards, moveLeft 1s forwards;
-webkit-animation-delay: 2s, 4s;
}
#-webkit-keyframes buttonFade {
0% {
opacity: 0;
}
80% {
opacity: 0;
}
100% {
opacity: 1;
}
}
You can actually concatenate the animation property further:
-webkit-animation: buttonFade 3s 2s 1 forwards, moveLeft 1s 4s forwards;
Removing the need to set animation duration separately The shorthand foranimation is:
animation: animation-name animation-duration animation-timing-function animation-delay animation-iteration-count animation-direction animation-fill-mode;

Two animations on same element not working

Fiddle | Source
At #lt, I used two animations,
animation: fadeInStamp .5s linear 1 normal both;
animation: leftArrowBounce .5s linear 1.5s 1 normal both;
But it doesn't work, even the first animation doesn't show work.
But if I remove the second one, the first starts working
CSS
#lt {
opacity: 0;
transform: scale(4);
animation: fadeInStamp .5s linear 1 normal both;
animation: leftArrowBounce .5s linear 1.5s 1 normal both;
}
#keyframes fadeInStamp {
0% { opacity: 0; }
30% { opacity: 1; }
60% { transform: scale(.7); }
80% { transform: scale(1.3); }
100% { opacity: 1; transform: scale(1); }
}
#keyframes leftArrowBounce {
0% { }
50% { transform: translateX(-10px); }
100% { transform: translateX(0); }
}
HTML
<div id="lt"><</div>
animation is like any other CSS, if you specify a new value for the property then it will (depending on specificity) override the old one. So when you include your leftArrowBounce animation, the fadeInStamp animation is being ignored.
In this case, you're not seeing anything happen because your element has an opacity of 0, but the leftArrowBounce animation is occuring as you can see by setting opacity: 1;:
http://jsfiddle.net/yfZ5k/1/
The size (i.e. scale) is also changing here because your leftArrowBounce is overwriting the transform property, and hence scale gets reset as part of the leftArrowBounce animation.
To include multiple animations, you can just comma-seperate them:
animation: fadeInStamp .5s linear 1 normal both,
leftArrowBounce .5s linear 1.5s 1 normal both;
HOWEVER, it seems that this is currently buggy when used in conjunction with a delay value. Certainly for Chrome:
https://code.google.com/p/chromium/issues/detail?id=178413
ALSO, the fact that you're changing transform in both animations, and have both of them with an animation-fill-mode set to both causes issues. It works in Firefox, Opera and IE using:
animation: fadeInStamp .5s linear 0s 1 normal forwards,
leftArrowBounce .5s linear 1.5s 1 normal forwards;
Along with setting the first frame of leftArrowBounce explicitly:
#keyframes leftArrowBounce {
0% { transform: translateX(0); }
50% { transform: translateX(-10px); }
100% { transform: translateX(0); }
}
DEMO: http://jsfiddle.net/yfZ5k/6/ (again, doesn't currently work in chrome)
Wrap one animation element with other
<div id="wrap-lt">
<div id="lt">
<
</div>
</div>
then add animation to each element
#wrap-lt {
display: inline-block;
vertical-align: bottom;
font: normal 15em/300px sans-serif;
color: #333;
opacity: 0;
-webkit-transform: scale(4);
-moz-transform: scale(4);
-ms-transform: scale(4);
-o-transform: scale(4);
transform: scale(4);
-webkit-animation: fadeInStamp .5s linear 1 normal both;
-moz-animation: fadeInStamp .5s linear 1 normal both;
-ms-animation: fadeInStamp .5s linear 1 normal both;
-o-animation: fadeInStamp .5s linear 1 normal both;
animation: fadeInStamp .5s linear 1 normal both;
}
#wrap-lt #lt{
-webkit-animation: leftArrowBounce .5s linear 1.5s 1 normal both;
-moz-animation: leftArrowBounce .5s linear 1.5s 1 normal both;
-ms-animation: leftArrowBounce .5s linear 1.5s 1 normal both;
-o-animation: leftArrowBounce .5s linear 1.5s 1 normal both;
animation: leftArrowBounce .5s linear 1.5s 1 normal both;
}
DEMO

Resources