我有两个图像在彼此的顶部,我正在使用CSS转换首先旋转顶部和底部图像,然后将底部图像旋转回来,创建一个翻转效果。然而,当动画状态立即改变到另一个图像时,我无法让它完美无瑕地工作。
JS
$('.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;
}
有人可以帮忙吗?
答案 0 :(得分:1)
我认为这正是您所寻找的,我创建了220px的方块(根据您的要求进行更改),其中包含您作为背景链接的图像。
<强> CSS 强>
.flip-container {
position:relative;
-webkit-perspective: 1000;
-moz-perspective: 1000;
-ms-perspective: 1000;
perspective: 1000;
}
.flip-container:hover .flipper {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
-ms-backface-visibility: hidden;
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform:rotateY(180deg);
transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
filter: FlipH;
-moz-filter: FlipH;
-ms-filter:"FlipH";
}
.flip-container, .front, .back {
width: 220px;
height: 220px;
}
.flipper {
-webkit-transition: 0.8s;
-webkit-transform-style: preserve-3d;
-ms-transition: 0.8s;
-ms-transform-style: preserve-3d;
-moz-transition: 0.8s;
-moz-transform-style: preserve-3d;
transition: 0.8s;
transform-style: preserve-3d;
position: relative;
}
.front, .back {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-ms-backface-visibility: hidden;
backface-visibility: hidden;
position: absolute;
color:red;
}
.front:hover {
transition: all 0.7s ease-in-out;
-moz-transition: all 0.7s ease-in-out;
-webkit-transition: all 0.7s ease-in-out;
}
.front
{
background:url('http://s27.postimg.org/ibckqwzub/black.png') no-repeat;
background-size:100% 100%;
}
.back {
-webkit-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
transform: rotateY(180deg);
filter: FlipH;
-ms-filter: FlipH;
background:url('http://s27.postimg.org/8pj0am8oj/rainbow.png') no-repeat;
background-size:100% 100%;
}
.front-title {
font-size:20px;
text-align:center;
}
.back-title {
font-size:25px;
text-align:center;
}
<强> HTML 强>
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="front-title">I am front Text</div>
</div>
<div class="back">
<div class="back-title">I am text behind </div>
</div>
</div>
</div>
答案 1 :(得分:1)
在您的小提琴中,只需将悬停的使用更改为鼠标悬停,就可以更好地使用代码。
$('.portfolio-pic-1').mouseover(function () {
$(this).toggleClass('portfolio-pic-1-hover');
$('.portfolio-pic-1-2').toggleClass('portfolio-pic-1-2-hover');
},
我喜欢 divy3993 发布的版本。干得好!