CSS Animation keyframe in NextJS not working - css

I currently have a very simple component in NextJS that is echo'ing HI at the moment. This component fades in on load, and I'm trying to pass a prop to it, to fade it out. Sounds simple enough, except, the fadeOut doesn't seem to be executing, even though the className renders on the page, albeit in transpiled form. I can't see what I'm doing wrong.
import styles from '../../styles/Hi.module.css'
import {useEffect, useState} from 'react';
const Hi = ({children, extraClass, navigateAway}) => {
const [className, setClassName] = useState(styles.hi);
useEffect(()=>{
if(navigateAway === true ) {
setClassName(styles.hiOut)
}
},[navigateAway]);
return (
<span onAnimationEnd={()=>setClassName(styles.hi + ' ' + styles.done)} className={className}>{children}</span>
);
};
export default Hi;
styles:
.hi {
display:inline-block;
animation-iteration-count: 1;
animation-delay: .1s;
animation: fadein 1s;
opacity: 0;
}
.hiOut {
display:inline-block;
animation-delay: .1s;
animation: fadeOut 3s;
border:1px solid red;
}
#keyframes fadein {
from { opacity: 0; }
to { opacity: 1; }
}
#keyframes fadeout {
0% { opacity: 0;}
100% { opacity: 1; }
}
For what its worth: via the Inspector on the page, the class renders this on inspecting it, and the red border 1px solid shows, my animation, not so much.
.Hi_hiOut__3g-I4 {
display: inline-block;
-webkit-animation-delay: .1s;
-moz-animation-delay: .1s;
animation-delay: .1s;
-webkit-animation: Hi_fadeOut__265f3 3s;
-moz-animation: Hi_fadeOut__265f3 3s;
animation: Hi_fadeOut__265f3 3s;
animation-duration: 3s;
animation-timing-function: ease;
animation-delay: .1s;
animation-iteration-count: 1;
animation-direction: normal;
animation-fill-mode: none;
animation-play-state: running;
animation-name: Hi_fadeOut__265f3;
border: 1px solid red;
}

Oh God. Kill me now.
animation: fadeOut 3s;
fadeout not fadeOut

Related

CSS Animation from opacity 0 to opacity 1 but then it goes back to opacity 0 again [duplicate]

This question already has answers here:
Maintaining the final state at end of a CSS animation
(5 answers)
Closed 8 months ago.
I have the following css:
.pagination {
opacity: 0;
animation-name: shownum;
animation-duration: 2s;
animation-delay: 1s;
}
#keyframes shownum {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
but when the page loads the buttons fade in like they are supposed to, but then disappear. So how do you stop the animation to not go back to its original state which I believe is happening in this case?
You need to set animation-fill-mode property to forwards.
.fade {
opacity: 0;
animation-name: shownum;
animation-duration: 2s;
animation-delay: 1s;
animation-fill-mode: forwards;
}
#keyframes shownum {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
<div class="fade">This div fades!</div>
Once the animation ends, your opacity will once again go to 0 as that is what you have defined in your css.
Simply remove that line and it will work:
.pagination {
animation-name: shownum;
animation-duration: 2s;
animation-delay: 1s;
}

Is there a conflict rule in css? My fadein keyframes works fine but my slidedown doesn't

Im using react and css. In my css file I create 2 animations:
#keyframes fadein {
0% {
visibility: hidden;
opacity: 0;
}
50% {
opacity: 0.5;
}
100% {
visibility: visible;
opacity: 1;
}
}
#keyframes slidedown {
0% {
transform: translateY(0%);
}
100% {
transform: translateY(30%);
}
}
.welcome__text {
padding: 3rem;
animation:
/* slidedown 2s ease 0s 1 normal forwards; => This one doesn't work */
/* fadein 1s ease-in 0s 1 normal forwards; => This one works */
}
here is my react file :
const Home = () => {
return (
<div className='homepage'>
<div className='welcome__text'>
<h1>Welcome</h1>
<h3> to Net's Web Game </h3>
</div>
</div>
)
}
export default Home;
My fadein keyframes works fine but my slidedown doesn't. And I don't know why. Is there any conflict css rule ?
If you're calling 2 animations on 1 element you need to separate them with commas, otherwise the last one (fadein) will just take priority as CSS is read from top to bottom, thus resulting in only 1 animation. For the animation properties, just separate them with commas as well:
#keyframes fadein {
0% {
visibility: hidden;
opacity: 0;
}
50% {
opacity: 0.5;
}
100% {
visibility: visible;
opacity: 1;
}
}
#keyframes slidedown {
0% {
transform: translateY(0%);
}
100% {
transform: translateY(30%);
}
}
.welcome__text {
padding: 3rem;
animation: slidedown 2s, fadein 1s;
animation-fill-mode: forwards;
animation-timing-function: ease 0s, ease-in 0s;
animation-direction: normal;
/* slidedown 2s ease 0s 1 normal forwards; => This one doesn't work */
/* fadein 1s ease-in 0s 1 normal forwards; => This one works */
}
<div class="welcome__text">hey there!</div>

How to refresh my animation sequence when all of my animations are done

I have multiple divs with animations, created in CSS, on my page. When the last div with animation is finished animating I wish to have the whole sequence to start over. My animations all have different delay times, and animations. I've tried the "animation: infinite" but what that achieves is the each individual animation will run again immediately after the animation has finshed. I need it start from the beginning after all of the animations have completed.
Anyone know how to achieve this?
Sample CSS
.openDiv {
width: 0px;
height: 513px;
background-image: url("CLS-circle-Ring-faded.png");
animation-name: grow;
animation-duration: 2s;
animation-fill-mode: forwards;
animation-delay: 2s;
transition-delay: 10s;
-webkit-animation-name: grow;
-webkit-animation-duration: 2s;
-webkit-animation-fill-mode: forwards;
-webkit-animation-delay: 2s;
-webkit-transition-delay: 10s;
}
#-webkit-keyframes grow {
0% {
width: 0px;
}
100% {
width: 1379px;
}
} /* Standard syntax */#keyframes grow {
0% {
width: 0px;
}
100% {
width: 1379px;
}
}

how do I delay a CSS3 transition before starting?

I'm trying to display an element, wait 1second and then fade out the element using css3 transitions.
Here is what I have:
.el {
-webkit-animation-timing-function: ease-in;
-webkit-animation-duration: 225ms;
-moz-animation-timing-function: ease-in;
-moz-animation-duration: 225ms;
animation-timing-function: ease-in;
animation-duration: 225ms;
}
#-webkit-keyframes fadeout {
from { opacity: 1; }
to { opacity: 0; }
}
#-moz-keyframes fadeout {
from { opacity: 1; }
to { opacity: 0; }
}
#keyframes fadeout {
from { opacity: 1; }
to { opacity: 0; }
}
.el {
opacity: 0;
-webkit-animation-duration: 500ms;
-webkit-animation-name: fadeout;
-webkit-animation-delay: 1000ms;
-moz-animation-duration: 500ms;
-moz-animation-name: fadeout;
-moz-animation-delay: 1000ms;
animation-duration: 500ms;
animation-name: fadeout;
animation-delay: 1000ms;
}
I thought animation-delay would be the way to go, but doing it like this, the element appears after 1000ms instead of fading out after 1000ms.
Any idea how to delay the fadeout?
Thanks!
Why not add the extra delay time to your animation duration:
-webkit-animation-duration: 1500ms;
Where ~66%(1000ms) of the time is a delay:
#-webkit-keyframes fadeout
{
0% { opacity: 1; }
66% { opacity: 1; }
100% { opacity: 0; }
}
Note that i used this time as an example. You can calculate the percentage of the delay yourself
jsFiddle
I hope this is what you meant.
Even though there is already a correct answer, let me enumerate what you options are.
You want an element to begin at opacity of 1, and stay like this for a second. Then, you want to fade it away to opacity of 0 during 0.5 s. And you want it to stay at opacity 0 forever.
The problem here is that the initial state and the final state are differents, so the base state of the element can not be both (of course!).
If we make the base state opacity 0, the problem is at the beginning. We can solve it as in nkmol solution. (starting the animation right away. We can also leave the animation only for the 0.5s where the opacity changes, and change the opacity usiong animation-fill-mode: backwards;
Also, you could set the base element to opacity 1. Then the problem is to make the final opacity 0; that can be done set animation-fill-mode: forwards;

How to remove animations from appearing only in IE?

I have a keyframe animation and I believe IE 10 is the only IE browser capable of playing this animation. How could I go about removing this animation if the browser is IE and keeping it otherwise (Chrome, Safari, FireFox)?
The animation looks like this:
// Animations
#-webkit-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
#-moz-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
#keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
.fade-in {
opacity: 0;
-webkit-animation: fadeIn ease-in 1;
-moz-animation: fadeIn ease-in 1;
animation: fadeIn ease-in 1;
-webkit-animation-fill-mode: forwards;
-moz-animation-fill-mode: forwards;
animation-fill-mode: forwards;
-webkit-animation-duration: .5s;
-moz-animation-duration: .5s;
animation-duration: .5s;
}
.fade-in.one {
-webkit-animation-delay: 0.5s;
-moz-animation-delay: 0.5s;
animation-delay: 0.5s;
}
.fade-in.two {
-webkit-animation-delay: 1.2s;
-moz-animation-delay: 1.2s;
animation-delay: 1.2s;
}
Fiddle
http://jsfiddle.net/mkerny45/6yYC9/
use conditional comments to turn the animations off. you'll need to use javascript to attach the cc's for ie10, and it should look like this:
<!--[if !IE]><!-->
<script>
// detect ie10, attach class of ie10 to html element
if(/*#cc_on!#*/false){document.documentElement.className+=' ie10';}
</script>
<!-->![endif]-->
<style>
.ie10 .animationclass{}
</style>
you can view gist here: https://gist.github.com/jalbertbowden/5174156
working demo of script here: http://dev.bowdenweb.com/ua/browsers/ie/ie10-detection-via-cc.html
i'v find IE10 does not read conditional comments anymore. .
so you can use jQuery:
if ($.browser.msie && $.browser.version == 10) {
$("html").removeClass("someClass");
}
or JavaScript:
if(Function('/*#cc_on return document.documentMode===10#*/')()){
document.documentElement.className ='';
}

Resources