I'm currently working on a project where I have two images stacked on top of each other. Using CSS transformations, I want to create a flip effect by first rotating both images away and then bringing the bottom image back in. However, I'm facing an issue where the animation state changes abruptly when unhovering.
JavaScript
$('.portfolio-pic-1').hover(function(){
$(this).toggleClass('portfolio-pic-1-hover');
$('.portfolio-pic-1-2').toggleClass('portfolio-pic-1-2-hover');
},
function()
{
$(this).toggleClass('portfolio-pic-1-unhover');
$('.portfolio-pic-1-2').toggleClass('portfolio-pic-1-2-unhover');
});
CSS
.portfolio-pic-1-hover {
-webkit-animation: rotate-away 1s 1 ease-in forwards;
/* Safari 4+ */
-moz-animation: rotate-away 1s 1 ease-in forwards;
/* Fx 5+ */
-o-animation: rotate-away 1s 1 ease-in forwards;
/* Opera 12+ */
animation: rotate-away 1s 1 ease-in forwards;
/* IE 10+, Fx 29+ */
}
.portfolio-pic-1-2-hover {
-webkit-animation: rotate-in 2s 1 ease-out forwards;
/* Safari 4+ */
-moz-animation: rotate-in 2s 1 ease-out forwards;
/* Fx 5+ */
-o-animation: rotate-in 2s 1 ease-out forwards;
/* Opera 12+ */
animation: rotate-in 2s 1 ease-out forwards;
/* IE 10+, Fx 29+ */
}
.portfolio-pic-1-unhover {
-webkit-animation: rotate-in 2s 1 ease-out forwards;
/* Safari 4+ */
-moz-animation: rotate-in 2s 1 ease-out forwards;
/* Fx 5+ */
-o-animation: rotate-in 2s 1 ease-out forwards;
/* Opera 12+ */
animation: rotate-in 2s 1 ease-out forwards;
/* IE 10+, Fx 29+ */
}
.portfolio-pic-1-2-unhover {
-webkit-animation: rotate-away 1s 1 ease-in forwards;
/* Safari 4+ */
-moz-animation: rotate-away 1s 1 ease-in forwards;
/* Fx 5+ */
-o-animation: rotate-away 1s 1 ease-in forwards;
/* Opera 12+ */
animation: rotate-away 1s 1 ease-in forwards;
/* IE 10+, Fx 29+ */
}
/* Chrome, Safari, Opera */
@-webkit-keyframes rotate-away {
0% {
-webkit-transform:rotateY(0deg);
-moz-transform:rotateY(0deg);
-ms-transform:rotateY(0deg);
-o-transform:rotateY(0deg);
transform:rotateY(0deg);
}
100% {
-webkit-transform:rotateY(90deg);
-moz-transform:rotateY(90deg);
-ms-transform:rotateY(90deg);
-o-transform:rotateY(90deg);
transform:rotateY(90deg);
}
}
/* Standard syntax */
@keyframes rotate-away {
0% {
}
100% {
-webkit-transform:rotateY(90deg);
-moz-transform:rotateY(90deg);
-ms-transform:rotateY(90deg);
-o-transform:rotateY(90deg);
transform:rotateY(90deg);
}
}
@keyframes rotate-in {
0% {
-webkit-transform:rotateY(90deg);
-moz-transform:rotateY(90deg);
-ms-transform:rotateY(90deg);
-o-transform:rotateY(90deg);
transform:rotateY(90deg);
}
50% {
-webkit-transform:rotateY(90deg);
-moz-transform:rotateY(90deg);
-ms-transform:rotateY(90deg);
-o-transform:rotateY(90deg);
transform:rotateY(90deg);
}
100% {
-webkit-transform:rotateY(0deg);
-moz-transform:rotateY(0deg);
-ms-transform:rotateY(0deg);
-o-transform:rotateY(0deg);
transform:rotateY(0deg);
}
}
/* Chrome, Safari, Opera */
@-webkit-keyframes rotate-in {
0% {
-webkit-transform:rotateY(90deg);
-moz-transform:rotateY(90deg);
-ms-transform:rotateY(90deg);
-o-transform:rotateY(90deg);
transform:rotateY(90deg);
}
50% {
-webkit-transform:rotateY(90deg);
-moz-transform:rotateY(90deg);
-ms-transform:rotateY(90deg);
-o-transform:rotateY(90deg);
transform:rotateY(90deg);
}
100% {
-webkit-transform:rotateY(0deg);
-moz-transform:rotateY(0deg);
-ms-transform:rotateY(0deg);
-o-transform:rotateY(0deg);
transform:rotateY(0deg);
}
}
.img-container {
position: relative;
height: 507px;
padding-bottom: 25px;
}
.img-container img {
position: absolute;
left: 25%;
overflow: hidden;
}
Is there anyone who can offer assistance with this issue?