我关注的是accepted answer here,效果很好。
但是,我想将框放在文档的不同部分,这会破坏动画。 js fiddle can be found here演示代码当前是如何工作的(错误地)
请参阅以下代码。
我希望我想要达到的目标是明确的。如果没有,我可以提供进一步的信息
HTML
<div class="wrapper">
<div class="background-out box-1"></div>
<div class="background-over box-1"></div>
<div class="background-info">
<div class="text">Text 1</div>
</div>
</div>
<div class="wrapper">
<div class="background-out box-2"></div>
<div class="background-over box-2"></div>
<div class="background-info">
<div class="text">Text 2</div>
</div>
</div>
CSS
.wrapper {
position: relative;
width: 100px;
height: 100px;
margin: 0 0 20px;
}
.background-out,
.background-over {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
.background-info {
position: absolute;
left: 100px;
top: 0;
width: 100%;
height: 100%;
visibility: hidden;
opacity: 0.2;
transform-origin: 0% 50% 0px;
transform: rotateY(-90deg);
background-color: grey;
}
.background-info .text {
padding: 5px;
}
.background-over {
background-color: green;
visibility: hidden;
opacity: 0;
transform-origin: 100% 50% 0px;
transform: rotateY(-90deg);
}
.wrapper:hover .background-out {
visibility: hidden;
}
.wrapper:hover .background-over,
.wrapper:hover .background-info {
transform: translate3d(0px,0px,0px) rotateY(0deg);
transition: opacity 600ms cubic-bezier(0.55, 0.31, 0.15, 0.93) 0ms,
-moz-transform 600ms cubic-bezier(0.55, 0.31, 0.15, 0.93) 0ms,
-webkit-transform 600ms cubic-bezier(0.55, 0.31, 0.15, 0.93) 0ms;
visibility: visible;
opacity: 1;
}
.box-1 {
background-color: pink;
left:200%;
top:100%;
}
.box-2 {
background-color: orange;
left:500%;
top:100%;
}
答案 0 :(得分:0)
你想用另一个包装器来包装它们来完成这个。
由于该卡的翻转效果取决于绝对定位,您不希望在同一个div元素上给出绝对定位。
<强> HTML 强>
<div class="box-1 box">
<div class="wrapper">
<div class="background-out"></div>
<div class="background-over"></div>
<div class="background-info">
<div class="text">Text 1</div>
</div>
</div>
</div>
<div class="box-2 box">
<div class="wrapper">
<div class="background-out"></div>
<div class="background-over"></div>
<div class="background-info">
<div class="text">Text 2</div>
</div>
</div>
</div>
<强> CSS 强>
.wrapper {
position: relative;
width: 100%;
height: 100%;
margin: 0 0 20px;
}
.background-out,
.background-over {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
.background-info {
position: absolute;
left: 100px;
top: 0;
width: 100%;
height: 100%;
visibility: hidden;
opacity: 0.2;
transform-origin: 0% 50% 0px;
transform: rotateY(-90deg);
background-color: grey;
}
.background-info .text {
padding: 5px;
}
.background-over {
background-color: green;
visibility: hidden;
opacity: 0;
transform-origin: 100% 50% 0px;
transform: rotateY(-90deg);
}
.wrapper:hover .background-out {
visibility: hidden;
}
.wrapper:hover .background-over,
.wrapper:hover .background-info {
transform: translate3d(0px,0px,0px) rotateY(0deg);
transition: opacity 600ms cubic-bezier(0.55, 0.31, 0.15, 0.93) 0ms,
-moz-transform 600ms cubic-bezier(0.55, 0.31, 0.15, 0.93) 0ms,
-webkit-transform 600ms cubic-bezier(0.55, 0.31, 0.15, 0.93) 0ms;
visibility: visible;
opacity: 1;
}
.box {
width: 100px;
height: 100px;
}
.box-1 {
position: absolute;
}
.box-2 {
top: 100px;
left: 200px;
position: absolute;
}