Animation transition effect need to be reduce on hover - css

I am trying to create animation, where on hover i am changing image from default image to hover image.
I am using CSS3 animation and keyframe properties,
CSS
.fader img {
transition: all 1s;
}
.fader img:last-child {
position: absolute;
top: 0;
left: 0;
opacity: 0;
}
.fader:hover img:first-child {
animation: toggle 2s infinite alternate 2s;
}
.fader:hover img:last-child {
opacity: 1;
animation: toggle 2s infinite alternate;
}
#keyframes toggle {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
HTML
<div class="fader">
<img src="http://placehold.it/200x200/000000" />
<img src="http://placehold.it/200x200/FFFFFF" />
</div>
I have created fiddle for the same
This is working fine , I need to do little change.
when one image change to next it leaves impression of the last one.
I am looking for the transition without footprint of last.
As given in fiddle , before black image comes, white image get slowly fade out then black comes, same happen from black to white. I want change without fade out effect.
I have tried
animation-timing-function: linear, ease, ease-in, ease-out, ease-in-out
but that doesn't work,
also i reduced delay time
animation-delay: .5s
but still that doesn't work. any idea ?

Related

Clicking on the play button should fade orange background into another color

This is what I have, I’m confused on how that would be set up.
What I want to occur is, after the button is clicked, I would want the orange to change to another color. Fade to another color.
.slide would need to be used for the animation to occur.
Similar to how .slide is used here:
.curtain1.slide .video-one {
transform: translateY(calc(-100% - 1px));
}
How would I do this in the code? https://jsfiddle.net/yo9amjub/
function openCurtain(curtain) {
curtain.classList.add("slide");
}
.video-one {
position: absolute;
height: 100%;
width: 100%;
top: 0;
transition: all 8s ease-in 0s;
transition-delay: 1s;
background: orange;
background-position: 0 0;
background-size: cover;
background-repeat: no-repeat;
z-index: 1;
animation: fadeInImage 2s ease-in 2s forwards;
opacity: 0;
}
#keyframes fadeInImage {
to {
opacity: 1;
}
}
Assuming that the goal is to make the orange box fade into another color while moving up at the same time, add this to the css code:
.video-one::before {
content: '';
position: absolute;
inset: 0;
opacity: 0;
transition: opacity 5s ease-in 2s;
background-color: pink;
}
.curtain1.slide .video-one::before {
opacity: 1;
}
To change which color for the orange box to fade into, edit background-color: pink; and change pink to a desired color.
To change the timing of the color fade, edit transition: opacity 5s ease-in 2s; first value 5s sets the duration for the secondary color to emerge, second value 2s sets the delay before the color fade starts.
The idea is to create a pseudo-element at the same position and on top of the orange box. This has the secondary color as background but is initially hidden with 0 opacity. When the orange box slides, turn it to full opacity with a transition to achieve the color-fade effect.

Remove delay after leaving the hover

I want to remove the delay I applied after leaving the hover state
I have a little box where I applied a hover effect with different delays. Everything works fine except my paragraph. I did a delay of 4.5s so it will pop out after the .goals-title is dissapeared. But after I leave the hover state it fades out way to slow. Is there a way to remove the delay on leaving the hover state.
/*thats the delay with the transition*/
.goals-text {
transition: opacity 0.75s ease-in-out;
transition-delay: 4.5s;
opacity: 0%;
}
/*the hover effect*/
.goals:hover > .goals-text {
opacity: 100%;
}
You can set a transition-delay that is longer when you hover the element :
/*thats the delay with the transition*/
.goals-text {
transition: opacity 0.75s ease-in-out;
transition-delay: 0s;
opacity: 0%;
}
/*the hover effect*/
.goals:hover > .goals-text {
opacity: 100%;
transition-delay: 2s;
}
<div class="goals">
v hover here v
<div class="goals-text">The animation starts after 2s on hover but immediately on mouse out</div>
^ hover here ^
</div>

Issue while applying fade in/fade out animation

I have a page with several buttons; clicking action on them triggers the fade-in/fade-out animation. During that animation, some contents of the div get changed.
Everything works fine, however, before fading animation starts, div disappears for some half of a second (and it doesn't look good). How can I prevent disappearing it, just get invisible and then visible again (without any changes to height)? Setting height to 100% didn't help.
CSS
.afterClick {
-webkit-animation: fadeinout 0.6s linear forwards !important;
animation: fadeinout 0.6s linear forwards !important;
}
#keyframes fadeinout {
from {
opacity: 1;
animation-timing-function: ease;
}
50% {
opacity: 0.5;
animation-timing-function: ease-in;
}
to {
opacity: 1;
animation-timing-function: ease-in-out;
}
}
HTML
<a href="#" class="some-class" (click)="setAnimation()">
<div class="afterClick" *ngIf="checkVisiblity == 'Y'">
some contents
</div>
TS
public checkVisiblity = 'Y';
setAnimation() {
let context = this;
context.checkVisiblity = 'N';
setTimeout(function() {
context.checkVisiblity = 'Y';
}, 50);
}
Try adding an animation-fill-mode to the .afterClick class
.afterClick {
-webkit-animation: fadeinout 0.6s linear forwards !important;
animation: fadeinout 0.6s linear forwards !important;
animation-fill-mode: backwards;}

Fade-out animation without fade-in, in CSS code

I have this CSS code to insert in my custom CSS field for my website
Here is my need: when I hover on my cart button, I want the box to appear immediately, and then when I remove the mouse, to fade out with an animation of 1,5 sec
So no fade-in animation, only fade-out animation
The box selector is: .header-cart.invisible
I have tried this first:
.header-cart.invisible {
transition: 1.5s;
}
.header-cart.invisible:hover {
visibility: visible;
opacity: 1;
}
But I have fade-out AND fade-in as well.
I have tried this other version, with transition attribute:
.header-cart.invisible {
transition: 0s 1.5s, opacity 1.5s linear;
}
.header-cart.invisible:hover {
visibility: visible;
opacity: 1;
}
This time, fade-in no longer displays, but the animation now interferes with my button "Add to Cart" : when I click on it, my cart box now displays with a 1.5 second delay, while I want it to display without any
So I have tried to add more code on the add to cart button to force it to display the cart box without delay, but I am unsuccessful:
.header-cart.invisible {
transition: 0s 1.5s, opacity 1.5s linear;
}
.header-cart.invisible:hover {
visibility: visible;
opacity: 1;
}
#add_to_cart_btn.button:active > .header-cart.invisible {
visibility: visible;
opacity: 1;
transition: 0s 0s !important;
transition-delay: 0s !important;
}
Would someone happen to have an idea so that it can fit my need, from any version of my code?
It would be great, thank you very much :)
PS: I really need this code to be 100% CSS, even if I know it would be more competitive using PHP or Javascript
when I hover on my cart button, I want the box to appear immediately, and then when I remove the mouse, to fade out with an animation of 1,5 sec So no fade-in animation, only fade-out animation
Then simply specify a transition of 1.5s duration for the normal state of the element (that it will be returning to after :hover), and 0s duration/no transition for the :hover state.
div {
margin: 1em;
padding: 1em;
border: 1px solid red;
}
div + div {
opacity: 0;
transition: 1.5s;
color: #fff;
background: #00f;
}
div:hover + div {
opacity: 1;
transition: none;
}
<div>hover me</div>
<div>whoop whoop</div>
Just don't add transitions when hover the cart button, then add ease-out transition when you hover the box div
.header-cart.invisible {
background-color:#000;
color:#fff;
opacity:0;
padding:20px;
border:solid 1px #ddd;
display:block;
}
.header-cart.invisible:hover {
transition: opacity 1.5s ease-out;
}
#add_to_cart_btn.buton
{
padding:20px;
border:solid 1px #ddd;
display:block;
}
#add_to_cart_btn.button:hover + .header-cart.invisible {
transition: none;
opacity:1;
}
<button id="add_to_cart_btn" class="button">
Cart Button - show box immediately
</button>
<button class="header-cart invisible">
Box - fade when hover
</button>
First, thank you for your reply
I am a bit unfamiliar with the "+" sign in selector
And I'm unsure I understood perfectly the "div" selector from CBroe
But I have tried both your methods from what I understood
1)
.header-cart.invisible {
position: fixed !important;
top: 25px !important;
transition: transition 1.5s !important;
}
.header-cart.invisible:hover {
visibility: visible;
opacity: 1;
}
#add_to_cart_btn.button:active + .header-cart.invisible {
visibility: visible;
opacity: 1;
transition: none !important;
}
So with this method, I have no fade-in and no fade-out.
Maybe my website behaves another way
You may try this URL: https://www.tresor-ethnique.com/collections/tibetain/products/pendentif-arbre-de-vie
And one issue I notice on your code snipped (based on my needs) is that "whoop whoop" disappears in spite me hovering it
2)
.header-cart.invisible {
position: fixed !important;
top: 25px !important;
transition: opacity 1.5s ease-out !important;
}
.header-cart.invisible:hover {
visibility: visible;
opacity: 1;
}
#add_to_cart_btn.button:active + .header-cart.invisible {
visibility: visible;
opacity: 1;
transition: none !important;
}
So with this method, I have fade-in but no fade-out.
Exactly the reverse I want... And I pretty much did the same way with other methods
Again maybe my website behaves in a certain way
Based on your code snippet, It's not exactly what I want to do (sorry if not clear)
I want :
if hover "Cart button" then box appears immediately => OK
if hover "Box" then box still here => not OK on your code snippet, it disappears with 1.5s animation
if remove from "Box" then 1.5s animation => not OK on your code snippet, it disappears immediately
if remove from "Cart button" then 1.5s animation => not OK on your code snippet, it disappears immediately
I hope this is more clear now :)

CSS animation delay behaves differently in Chrome than in IE/Firefox

I'm having some issues when using a delay with CSS animation.
My desired effect in the example:
The red box starts transparent waits 1 second, then fades in.
This happens in Chrome.
However, the behaviour in IE and Firefox is different:
The box starts visible, waits 1 second, then disappears and fades back in.
Which behaviour is correct? It seems to me that if you're going to delay an animation, it makes sense to wait at the first frame of the animation, not the last frame.
Is there a workaround without Javascript?
#-webkit-keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.box {
height: 200px;
width: 200px;
background: red;
-webkit-animation: fadeIn 1s 1s;
animation: fadeIn 1s 1s;
}
<div class="box"></div>
You could use animation-fill-mode to determine how to 'fill' your animation when it ends. You can revert it to before, after, initial, etc... Its not the most intuitive naming convention, but it does allow you to set your animation to start with opacity : 0; and then retain the computed value you want after the animation using animation-fill-mode: forwards;.
MDN has a good explanation for it: https://developer.mozilla.org/en-US/docs/Web/CSS/animation-fill-mode

Resources