How to Set The Current Frame (Or Similar) of a CSS Animation

When using ''@keyframe play'' in css, how can you get the frame the animation is currently at with javascript?

Get the element you would like to get the current background-position for, and use:

getComputedStyle(element).getPropertyValue("background-position");

I might recommend recoding it to use JavaScript however, since it will be more efficient to interact with programmatically, and there won't be any noticeable performance hit in modern browsers if you use requestAnimationFrame based animation.

More information about getComputedStyle on MDN.

Seek to specific keyframe in css3 animation

You can seek to a specific keyframe by using a negative animation-delay value.

How to transition CSS display + opacity properties

Based on Michaels answer this is the actual CSS code to use

.parent:hover .child
{
display: block;

-webkit-animation: fadeInFromNone 0.5s ease-out;
-moz-animation: fadeInFromNone 0.5s ease-out;
-o-animation: fadeInFromNone 0.5s ease-out;
animation: fadeInFromNone 0.5s ease-out;
}

@-webkit-keyframes fadeInFromNone {
0% {
display: none;
opacity: 0;
}

1% {
display: block;
opacity: 0;
}

100% {
display: block;
opacity: 1;
}
}

@-moz-keyframes fadeInFromNone {
0% {
display: none;
opacity: 0;
}

1% {
display: block;
opacity: 0;
}

100% {
display: block;
opacity: 1;
}
}

@-o-keyframes fadeInFromNone {
0% {
display: none;
opacity: 0;
}

1% {
display: block;
opacity: 0;
}

100% {
display: block;
opacity: 1;
}
}

@keyframes fadeInFromNone {
0% {
display: none;
opacity: 0;
}

1% {
display: block;
opacity: 0;
}

100% {
display: block;
opacity: 1;
}
}


Related Topics



Leave a reply



Submit