Some css #keyframes animation opacity issues - css

Can anybody explain why this code doesn't hide elemens between 95-100%? I want to show hidden by opacity object and hide it after animation. I have no idea why it doesn't work.
button {
opacity: 0;
animation: button 6s linear infinite 0s;
}
#keyframes button {
0% {
opacity: 0;
transform: translateY(64px);
}
5% {
opacity: 1;
transform: translateY(0px);
}
95% {
opacity: 1;
}
100% {
opacity: 0;
}
}
<button>example</button>

Related

How can i do animations to show item CSS

am looking for a solution to make some animations on an item when we try to load the next one.
Here is what i have:
Before i click i have this :
After Click:
I want to show the image in background when i click on the list element at the right side (Man, Woman...).
The backgroud image is hidden on the right, it exceeds the screen and this one is resized.
I need to hide the backgroundimage without resizing the screen, and show it when click with animation.
CSS:
img.slider__bg {
width: 100%;
position: absolute;
transform: translateX(100%);
-webkit-transform: translateX(100%);
transition: transform .5s 4s;
&.showBg {
animation: showBg 0.5s forwards;
-webkit-animation: showBg 0.5s forwards;
}
&.hideBg {
animation: hideBg 0.5s forwards;
-webkit-animation: hideBg 0.5s forwards;
}
#keyframes showBg {
100% { transform: translateX(0%); }
}
#-webkit-keyframes showBg {
100% { -webkit-transform: translateX(0%); }
}
#keyframes hideBg {
0% { transform: translateX(0%); }
100% { transform: translateX(100%); }
}
#-webkit-keyframes hideBg {
0% { -webkit-transform: translateX(0%); }
100% { -webkit-transform: translateX(100%); }
}
}
Use conditional rendering to display the background image when you click. You need to declare a state to identify whether you clicked or not.

delaying an animation for x seconds with css

I have an element I would like to fade in and fade out but show for 10 seconds.
.element {
-webkit-animation: fadeinout 2s linear forwards;
transition-delay: 10s;
animation: fadeinout 2s linear forwards;
opacity: 0;
}
#-webkit-keyframes fadeinout {
50% { opacity: 1; }
}
#keyframes fadeinout {
50% { opacity: 1; }
}
I have been trying for a while and think I have completely miss understood something.
UPDATE -----
What I'm trying to do is for the element to fade in over 2 seconds then show for 10 secs then fade out over 2 seconds.
transition-delay is wrong. It is about the transition. The equivalent of that is: animation-delay. use animation-duration: 14s for the time of running animation. or:
.element {
-webkit-animation: fadeinout 14s linear forwards;
animation: fadeinout 14s linear forwards;
opacity: 0;
width: 100px;
height: 100px;
background-color: red;
}
#-webkit-keyframes fadeinout {
14% { opacity: 1; }
86% { opacity: 1; }
100% { opacity: 0; }
}
#keyframes fadeinout {
14% { opacity: 1; }
86% { opacity: 1; }
100% { opacity: 0; }
}
<div class="element"></div>
This may be a little verbose, but if it is acceptable for your fade duration to be proportional to the duration it is shown you could use a keyframe structure like this:
#keyframes fadeinout {
0% { opacity: 0; },
10% { opacity: 1; },
90% { opacity: 1; },
100% { opacity: 0; }
}
To get a 2 second fadein, a 'stay there' for 10 seconds and then a 2 second fadeout you have an overall animation time of 14 seconds.
For the first (2 / 14) * 100% [=14.29%] you want the opacity to go from 0 to 1
For the next (10 / 14) * 100% [=71.43%] you want the opacity to stay at 1
For the last (2 / 14) * 100% [=14.29%] you want the opacity to go from 1 to 0.
So the animation keyframes look like this:
#keyframes fadeinout {
0%, 100% { opacity: 0; }
14.29%, 85.72% { opacity: 1; }
}
You don't want a delay on your animation (animation-delay just delays the start of an animation).
Current CSS does not allow us to use a calc function in the % settings in keyframes so we've had to do the calculation in advance and build it in (it didn't seem worth going to more than a couple of decimal places).
.element {
animation: fadeinout 14s linear forwards;
opacity: 0;
width: 20vmin;
height: 20vmin;
background-color: magenta;
}
#keyframes fadeinout {
0%,
100% {
opacity: 0;
}
14.29%,
85.72% {
opacity: 1;
}
}
<div class="element"></div>

React fade in and fade out with pure css

I am new to React. I have a small app with a login button. When I click the login button and a error from the backend is triggered, a toast error message is rendered. I want to show a animation fade-in and fade out from bottom to top. Only the fade in animation for the toast message is currently working. But how can i trigger a fade out animation?
the errorMessage comes from the redux mapStateToProps function. The clearAuthErrorAction is an action, it will delete the error message from the redux state.
<AuthenticationAlert errorMessage={errorMessage}>
{setTimeout(() => clearAuthErrorAction(), 3000)}
</AuthenticationAlert>
.toast__container {
...
animation: slideInTop 0.5s linear;
}
#keyframes slideInTop {
0% {
transform: translateY(-1.5rem);
opacity: 0;
}
100% {
transform: translateY(0);
opacity: 1;
}
}
#keyframes slideInBottom {
0% {
transform: translateY(1.5rem);
opacity: 0;
}
100% {
transform: translateY(0);
opacity: 1;
}
}
The solution was simple. I adjusted the animation in CSS a little bit.
#keyframes slideInTop {
0% {
transform: translateY(-3rem);
opacity: 0;
}
50% {
transform: translateY(0);
opacity: 1;
}
100% {
transform: translateY(-20rem);
opacity: 0;
}
}

Animation Display Block to Display None - CSS

Display None to Display Block animation is working
but I need the animation to work this way also
- Animation Display Block to Display None
the animations is not working when action go from block to Display None
have an idea what can be the problem?
#dboldDiv,#dbnewDiv {
animation: anim .4s ease-in-out;
}
#keyframes anim {
0% {
display: none;
opacity: 0;
}
1% {
display: block;
opacity: 0;
transform: scale(0.8);
}
100% {
opacity: 1;
transform: scale(1);
}
}
display is not animatable property
There are two category of properties animatable and not animatable
you can check animated properties list from here :
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_animated_properties
display:none won't work smooth.
For fluent disappearing try using visibility:hidden, or if just keep 0 opacity and add pointer-events:none, so the object doesn't catch any mouse events.
document.getElementById('hide').addEventListener('click', function(){
document.getElementById('link').className = 'hide';
});
document.getElementById('show').addEventListener('click', function(){
document.getElementById('link').className = 'show';
});
document.getElementById('link').addEventListener('click', function(){
alert('clicked');
});
#link {
display:block;
}
#link.show {
animation: anim1 .4s;
animation-fill-mode: forwards;
}
#link.hide {
animation: anim2 .4s;
animation-fill-mode: forwards;
animation-direction: reverse;
}
#keyframes anim1 {
0% {
opacity: 0.3;
pointer-events:none;
}
100% {
opacity: 1;
pointer-events:all;
}
}
#keyframes anim2 {
0% {
opacity: 0.3;
pointer-events:none;
}
100% {
opacity: 1;
pointer-events:all;
}
}
<button id="hide">Hide</button>
<button id="show">Show</button>
hidding & showing

CSS keyframe animations and delay?

I have a keyframe animation, that infinitly loops.
-webkit-animation: fade 3s ease-in-out infinite;
#-webkit-keyframes fade {
0% { opacity: 0; -webkit-transform: rotate(0deg);}
20% { opacity: 1; -webkit-transform: rotate(360deg);}
100% { opacity: 0; -webkit-transform: rotate(360deg);}
}
How can I delay each ilteration of the loop. im aware I can delay teh entire animation, but this only occurs once. I wish to do it everytime.
Unfortunately there is no current option to easily put a delay between the iterations, but instead you can add another stop with the same values (as I commented), and increase the duration:
#keyframes fade {
0% { opacity: 0; transform: rotate(0deg); }
10% { opacity: 1; transform: rotate(360deg); }
50% { opacity: 0; transform: rotate(360deg); }
100% { opacity: 0; transform: rotate(360deg); }
}
.selector {
animation: fade 6s ease-in-out infinite; /* increased duration */
}
Demo at http://jsfiddle.net/PW8Ur/2/
If you need scripted control over when you want to restart an animation, you could have a look at: http://css-tricks.com/restart-css-animation/

Resources